【发布时间】:2018-05-10 04:53:33
【问题描述】:
我有一个父模块,我在其中延迟加载一个子模块
如您所见,我没有直接导入我的子模块,而是在路由文件下懒惰地加载它:
父模块:
@NgModule({
imports: [
CommonModule,
ParentRoutingModule,
],
exports: [
ParentRoutingModule
],
declarations: [ParentComponent]
})
export class ParentModule { }
父路由模块:
const parentRoutes: Routes = [
{path: '', component: ParentHomeComponent},
{
path: '',
loadChildren: () => ChildModule,
canLoad: [ChildModuleGuard]
},
];
@NgModule({
imports: [
CommonModule,
RouterModule.forChild(parentRoutes)
],
declarations: [],
exports: [
RouterModule
]
})
export class ParentRoutingModule { }
在我的主要 ParentModule 组件中; ParentHomeComponent 我想注入我的 ChildHomeCOmponent 的视图,如下所示:
<p>
Parent-home works!
</p>
<app-Child-home></app-Child-home>
但这会引发一个错误,指出 ChildHomeComponent 不是 ParentModule 的一部分(因为我没有直接导入它);
如何处理??
我希望 如果模块已加载,我的 child home 组件t 会显示在 parent home 组件
下建议??
【问题讨论】:
-
我不认为这是可能的,因为延迟加载的模块将在其路由之一被调用时加载,而以前从未加载过,如果您在主模块中需要此组件,则必须导入它或将其添加到共享模块中
-
你解决了吗?我有一个类似的问题
标签: javascript angular angular-ui-router lazy-loading router