角度将组件从模块传递到App模块中的另一个模块

时间:2018-09-26 09:44:23

标签: angular module components ng-modules

我在确定如何从导入到Angular应用程序中的模块中传递组件并将其在我也导入到我的App中的另一个模块中使用时遇到问题。

请注意,所有这两个模块都是我创建的模块。

那是我的app.module.ts:

@NgModule({
  declarations: [
    AppComponent,
    HomeComponent,
    PnDashboardComponent,
    PnFormulaireComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    LayoutModule.forRoot(environment.layout),
    DispoModule.forRoot(environment.dispoAides)
  ],
  providers: [
    ErrorsHandler,
    InitialisationService,
    InitializationGuard
  ],
  bootstrap: [AppComponent]
})

我想要做的是将一个名为BreadcrumbComponent的组件从LayoutModule传递到DispoModule,并希望能够在该模块内部使用它。

请注意,LayoutModule和DispoModule是依赖的角度模块项目,它们与ng-packagr打包并导入到我的应用程序中。

谢谢。

2 个答案:

答案 0 :(得分:1)

您需要创建一个 SharedModule 并在其中声明 BreadcrumbComponent 。还要导出组件,以便我可以在其他模块中使用。

在要在应用程序中使用BreadcrumbComponent的任何地方导入SharedModule

答案 1 :(得分:1)

如果您要做的是将一个名为BreadcrumbComponent的组件从LayoutModule传递到DispoModule,并希望能够在该模块中使用它。

然后写

exports: [
    BreadcrumbComponent
]

在您的LayoutModule

并在LayoutModule中导入DispoModule

相关问题