Angular6 使用两个共享模块:组件不是已知元素:

Angular 6 Using Two Shared Module : Component is not a known element:

我有两个共享模块 'shared-candidate-login-reg.module.ts' 和 'shared.module.ts',我正在我的主页中导入这两个共享模块。我想在我的 'WidgetLogRegComponent' 组件(它是我主页的子组件,也是我的 'shared-candidate-login-reg.module' 的一部分)中使用 'shared.module.ts' 中的 'AlertLblComponent'。我也在使用延迟加载。为什么我无法在我的主页模块中获取 'alert-lbl' 组件?

我的alert.module.ts

import { AlertLblComponent } from './../directives';
import { AlertService } from './../services/alert.service';
@NgModule({
    declarations: [
        AlertLblComponent
    ],
    imports: [
        CommonModule,
    ],
    providers: [
        AlertService,
    ],
    exports: [
        CommonModule,
        AlertLblComponent
    ]    
  })
  export class SharedModule {} 

共享候选人登录-reg.module.ts

import { WidgetLogRegComponent } from './../candidates/widget-log-reg/widget-log-reg.component';
@NgModule({
  imports: [
    CommonModule,
  ],
  declarations: [
    WidgetLogRegComponent
  ],
  exports: [
    WidgetLogRegComponent 
 ]
})
export class ShareCandidateLoginRegdModule { }

home.module.ts

import {ShareCandidateLoginRegdModule} from './../shared/shared-candidate-login-reg.module';
import {SharedModule} from './../shared/shared.module';

@NgModule({
  declarations: [
    HomeComponent
      ], 
  providers: [CandidateService,JobService],
  imports: [
    CommonModule,
    SharedModule,
    ShareCandidateLoginRegdModule,
    HomeRoutingModule,
  ],
  exports: [HomeComponent],

})
export class HomeModule { }

home.component.html

<div class="col-md-4 banner-form">
  <app-widget-log-reg></app-widget-log-reg>
 </div>

widget-log-reg.component.html

<alert-lbl></alert-lbl>
<div class="page-tab">
   <div id="form-login">
    ......
   </div>
</div>

警报-lbl.component.ts

import { Component, OnInit, OnDestroy } from '@angular/core';
import { Subscription } from 'rxjs';
import { AlertService } from './../services';

@Component({
    selector: 'alert-lbl',
    templateUrl: 'alert-lbl.component.html'
})
export class AlertLblComponent implements OnInit, OnDestroy {
    private subscription: Subscription;
    message: any;
    constructor(private alertService: AlertService) { }
    ngOnInit() {
        this.subscription = this.alertService.getMessage().subscribe(message => { 
            this.message = message; 
        });
    }
    ngOnDestroy() {
        this.subscription.unsubscribe();
    }
}

警报-lbl.component.html

<div *ngIf="message" [ngClass]="{ 'alert': message, 'alert-success': message.type === 'success', 'alert-danger': message.type === 'error' }">{{message.text}}</div>

我正在处理这个错误:

Uncaught (in promise): Error: Template parse errors:
'alert-lbl' is not a known element:

您没有导入 SharedModule,它在 ShareCandidateLoginRegdModule 中导出 alert-lbl 组件。如下导入即可

@NgModule({
  imports: [
    CommonModule,
    SharedModule // <-- import shared module here
  ],
  declarations: [
    WidgetLogRegComponent
  ],
  exports: [
    WidgetLogRegComponent 
 ]
})
export class ShareCandidateLoginRegdModule { }