[英]Angular pass a component from a module to another module in the App module
I have an issue figuring out how I can pass a component from a module I import into my Angular application and use it inside another module that I import also in my App. 我在解决如何从导入到Angular应用程序中的模块传递组件并将其在我也导入到App中的另一个模块中使用时遇到问题。
Note that all those two modules are modules I created. 请注意,所有这两个模块都是我创建的模块。
That's my app.module.ts : 那就是我的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]
})
What I want to do is pass a component let's say called BreadcrumbComponent
from the LayoutModule
to the DispoModule
and beeing able to use it inside that module. 我想要做的是将一个名为
BreadcrumbComponent
的组件从LayoutModule
到DispoModule
并DispoModule
能够在该模块内使用它。
Note that LayoutModule and DispoModule are dependent angular module project that are packaged with ng-packagr and imported in my Application. 请注意,LayoutModule和DispoModule是依赖的角度模块项目,与ng-packagr打包在一起并导入到我的应用程序中。
Thank you. 谢谢。
You need to create a SharedModule
and declare the BreadcrumbComponent
in it. 您需要创建一个
SharedModule
并在其中声明BreadcrumbComponent
。 Also export the component so that i can be used across other Modules. 还导出组件,以便我可以在其他模块中使用。
Import the SharedModule wherever you want to use BreadcrumbComponent in the application 导入要在应用程序中使用BreadcrumbComponent的任何位置的SharedModule
If you want to do is pass a component let's say called BreadcrumbComponent
from the LayoutModule
to the DispoModule
and beeing able to use it inside that module. 如果您想做的就是将一个名为
BreadcrumbComponent
的组件从LayoutModule
到DispoModule
,并且可以在该模块中使用它。
then write 然后写
exports: [
BreadcrumbComponent
]
in your LayoutModule
在您的
LayoutModule
and import LayoutModule
in DispoModule
进口
LayoutModule
在DispoModule
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.