[英]Error: Type Component is part of the declarations of 2 modules
我在 ionic 頁面的 HTML 中調用一個組件,因此我將該組件添加到 page.module.ts 的聲明數組中:
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
DeleteFriendsPageRoutingModule
],
declarations: [DeleteFriendsPage,CommunityCardAccordionComponent,GroupTabsComponent],
entryComponents: []
})
export class DeleteFriendsPageModule {}
我收到了這個錯誤:
錯誤:類型 CommunityCardAccordionComponent 是 2 個模塊聲明的一部分:CommunityPageModule 和 DeleteFriendsPageModule。 請考慮將 CommunityCardAccordionComponent 移至導入 CommunityPageModule 和 DeleteFriendsPageModule 的更高模塊。 您還可以創建一個新的 NgModule 導出並包含 CommunityCardAccordionComponent 然后將該 NgModule 導入 CommunityPageModule 和 DeleteFriendsPageModul
問題正如錯誤所說
CommunityCardAccordionComponent 是 2 個模塊聲明的一部分
簡單來說,您不能在多個模塊中聲明一個組件...
另一方面,您可以多次導入同一個模塊,因此您的解決方案是簡單地使用模塊,請按照以下步驟操作
從CommunityPageModule and DeleteFriendsPageModule
刪除CommunityCardAccordionComponent
在你的path/to/community-card-accordion-component/中,創建一個模塊CommunityCardAccordionModule
@NgModule({
imports: [CommonModule],
declarations: [CommunityCardAccordionComponent]
})
export class CommunityCardAccordionModule { }
CommunityPageModule and DeleteFriendsPageModule
中導入CommunityCardAccordionModule
就是這樣,你解決了問題,現在CommunityCardAccordionComponent
只在一個模塊中聲明
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.