首页 > 解决方案 > Angular 导入子模块导致父模块的组件损坏

问题描述

我有一个carModule包含两个组件carcar-detail. 我需要使用从组件中调用的另一个模块命名的wheel另一个组件。wheelModulecar-detail

我正在导出wheelComponentinwheel.module.ts然后添加wheelModulecar.module.ts文件中(在 的imports部分中@NgModule)。

现在我可以访问wheel's 的组件 HTML tag( <wheelDetail></wheelDetail>)car-detail.component.html并且它工作正常。

问题是现在,调用的主要car组件被car.component.html破坏并显示wheel组件的内容而不是car组件的内容!!!

/vehicle/car/

car-detail.component.html
car-detail.component.ts
car.component.html
car.component.ts
car.modules.ts

/vehicle/wheel/

wheel.component.html
wheel.component.ts
wheel.modules.ts

关于如何解决它的任何想法?

wheel.module.ts

@NgModule({
      declarations: [
        wheelComponent
      ],
      imports: [
        ...,
        DxPopupModule,
        ...
      ],
      exports: [
        wheelComponent
      ]
})

car.module.ts

@NgModule({
      declarations: [
        carComponent,
        carDetailComponent
      ],
      imports: [
        ...,
        wheelModule,
      ]
})

标签: angularangular-componentsangular-module

解决方案


推荐阅读