I'm trying to include a Component
in 2 modules (parent and child) but getting various errors in the process
app.module.ts
@NgModule({
declarations: [SharedComponent],
exports: [SharedComponent]...
})
child.module.ts
@NgModule({
imports: [SharedComponent], //Unexpected directive imported by module
})
app.html
<div class="container">
<shared-selector></shared-selector>
<child-selector></child-selector>
</div>
child.html
<div>
content
<shared-selector></shared-selector>
</div>
I'm loading the ChildModule in Async matter
loadChildren: 'app/child.module#ChildModule',
When not importing
or declaring
in the ChildModule
I'm getting the error:
template parse error: shared-selector is not a known element
****** UPDATE *******
when Creating FeatureModule
, in order to work the SharedModule
should export the Components...updateed code...
SharedModule
@NgModule({
imports: [
CommonModule
],
declarations: [
SharedComponent
],
exports: [
SharedComponent
]
})
export class SharedModule {}
app.module.ts
@NgModule({
imports: [ChildModule, SharedModule],...
})
child.module.ts
@NgModule({
imports: [SharedModule], //Unexpected directive imported by module
})
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…