当前有个 header.component.ts 公共头部组件,我在 app.module.ts 注册后,无法其他模块中使用。
其他的模块也已经在app.module.ts 注册。
app.module.ts
@NgModule({
declarations : [ HeaderComponent ],
imports : [ otherModule ] // 其他子模块
})
other.module.ts
@NgModule({
...........
})
export class otherModule {}
other.component.ts
<div class="other-component">
<header-component></header-component>
</div>
报错 :
'header-component' is not a known element:
If 'header-component' is an Angular component, then verify that it is part of this module.
子模块是不能导入父模块里面的组件的,你想要共享header组件的话,就在每个要用的模块里面导入header组件。
共享模块也是父模块可以使用子模块里面exports出来的东西,你把需要共享的东西加入到一个模块里面,然后在其他模块导入