我有两个共享的模块化“ shared-candidate-login-reg.module.ts”和“ shared.module.ts”,我将这两个共享模块都导入到我的主页中。我想在我的'WidgetLogRegComponent'组件(这是我的主页的子组件,也是我的'shared-candidate-login-reg.module'的一部分)的'shared.module.ts'中使用'AlertLblComponent' ')。我也在使用延迟加载。为什么我的Home Module中无法获得“ 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 {}
shared-candidate-login-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>
alert-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();
}
}
alert-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:
答案 0 :(得分:3)
您没有导入SharedModule
,而该alert-lbl
导出了ShareCandidateLoginRegdModule
中的@NgModule({
imports: [
CommonModule,
SharedModule // <-- import shared module here
],
declarations: [
WidgetLogRegComponent
],
exports: [
WidgetLogRegComponent
]
})
export class ShareCandidateLoginRegdModule { }
组件。只需按以下步骤导入
numpy.mgrid