[英]Use component lazy loading in multi components angular?
I have Three components ( NavbarComponent , IndexComponent , PoweredComponent ) so I use lazy loading I need use components in multi components ,I don't know how to declare the component for using it in the lazy module.我有三个组件( NavbarComponent , IndexComponent , PoweredComponent )所以我使用延迟加载我需要在多个组件中使用组件,我不知道如何声明组件以在惰性模块中使用它。 I'll show you some of the relevant parts of the different files:
我将向您展示不同文件的一些相关部分:
declarations: [NavbarComponent],
imports: [
CommonModule
],
exports: [NavbarComponent]
})
declarations: [IndexComponent ,NavbarComponent],
imports: [
CommonModule,
IndexRoutingModule,
],
})
index.component.html index.component.html
<app-navbar></app-navbar>
<div>...</div>
in index show navbar在索引中显示导航栏
@NgModule({
declarations: [PoweredComponent,NavbarComponent],
imports: [
CommonModule,
PoweredRoutingModule,
],
})
powered.component.html power.component.html
<app-navbar></app-navbar>
<div>...</div>
in powered.component.html
no show navbar在
powered.component.html
没有显示导航栏
issue
<app-navbar></app-navbar>
not dispaly in multi components can show jsut in index componentsissue
<app-navbar></app-navbar>
not dispaly in multi components can show jsut in index components
Pleas help me???请帮帮我???
Thank's to read!!!感谢阅读!!!
You can't declare a Component (using declarations
) in more than one NgModule.你不能在多个 NgModule 中声明一个组件(使用
declarations
)。 In your situation, as your NavbarModule
exports the NavBarComponent
, you just need to import the module in the PoweredModule
and IndexModule
to make the Component available in these modules.在您的情况下,当您的
NavbarModule
导出NavBarComponent
,您只需要在PoweredModule
和IndexModule
导入模块即可使 Component 在这些模块中可用。
So for IndexModule
as an example :所以以
IndexModule
为例:
declarations: [IndexComponent],
imports: [
CommonModule,
IndexRoutingModule,
NavbarModule
],
})
Index.module.ts索引.module.ts
declarations: [IndexComponent],
imports: [
CommonModule,
IndexRoutingModule,
NavbarModule
],
})
powered.module.ts power.module.ts
@NgModule({
declarations: [PoweredComponent],
imports: [
CommonModule,
PoweredRoutingModule,
NavbarModule
],
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.