我想包括Component
在2個模塊(父母和子女),但得到的過程中的各種錯誤共享組件moduls之間2
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>
我加載了ChildModule在異步事
loadChildren: 'app/child.module#ChildModule',
當不importing
或declaring
在ChildModule
我越來越錯誤:
template parse error: shared-selector is not a known element
****** UPDATE *******
創建FeatureModule
時,爲了工作SharedModule
應該導出組件... updateed代碼...
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
})
我明白這樣一個事實。我不明白爲什麼它不工作,如果我'導出'它在父模塊,並將其導入Childmodule – royB
更新我的問題,使其更清楚.. – royB
'進口'只適用於模塊,而不是組件和它是'進口'而不是'進口'。我懷疑如果'app.module'輸出共享組件,它會解決問題。改爲將其設爲'SharedModule'或'MyFeatureModule'。 –