在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/HTML5  HTML/ angular2 主模塊與子模塊之間如何共享組件?

angular2 主模塊與子模塊之間如何共享組件?

當(dāng)前有個(gè) header.component.ts 公共頭部組件,我在 app.module.ts 注冊(cè)后,無法其他模塊中使用。
其他的模塊也已經(jīng)在app.module.ts 注冊(cè)。

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>

報(bào)錯(cuò) :

'header-component' is not a known element:
If 'header-component' is an Angular component, then verify that it is part of this module.
回答
編輯回答
尐懶貓
  1. 在其他模塊導(dǎo)入
  2. 或者全局導(dǎo)入
2018年4月14日 09:37
編輯回答
下墜

子模塊是不能導(dǎo)入父模塊里面的組件的,你想要共享header組件的話,就在每個(gè)要用的模塊里面導(dǎo)入header組件。
共享模塊也是父模塊可以使用子模塊里面exports出來的東西,你把需要共享的東西加入到一個(gè)模塊里面,然后在其他模塊導(dǎo)入

2017年9月28日 01:53