简体   繁体   中英

Error: Type Component is part of the declarations of 2 modules

i am calling a component in the HTML of a page in ionic, so i added the component to the declarations array of the page.module.ts:

@NgModule({
  imports: [
    CommonModule,
    FormsModule,
    IonicModule,
    DeleteFriendsPageRoutingModule
  ],
  declarations: [DeleteFriendsPage,CommunityCardAccordionComponent,GroupTabsComponent],
  entryComponents:  []
})
export class DeleteFriendsPageModule {}

i got this error:

Error: Type CommunityCardAccordionComponent is part of the declarations of 2 modules: CommunityPageModule and DeleteFriendsPageModule. Please consider moving CommunityCardAccordionComponent to a higher module that imports CommunityPageModule and DeleteFriendsPageModule. You can also create a new NgModule that exports and includes CommunityCardAccordionComponent then import that NgModule in CommunityPageModule and DeleteFriendsPageModul

The problem is as the error says

CommunityCardAccordionComponent is part of the declarations of 2 modules

In simple terms, you cannot declare a component in more than one module...

On the other hand you can import the same module more than once, So your solution is to simply use modules, follow this steps

  1. Remove CommunityCardAccordionComponent from BOTH CommunityPageModule and DeleteFriendsPageModule

  2. Inside your path/to/community-card-accordion-component/ , create a module CommunityCardAccordionModule

@NgModule({
  imports: [CommonModule],
  declarations: [CommunityCardAccordionComponent]
})
export class CommunityCardAccordionModule { }
  1. Import CommunityCardAccordionModule in both CommunityPageModule and DeleteFriendsPageModule

Thats it, you solve the issue, now CommunityCardAccordionComponent is only declared in one module

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM