我有一个父模块,在该模块中,我延迟加载(子模块)
正如您可能看到的,我不直接导入我的子模块,但是我在路由文件下缓慢地加载它:
父模块:
@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 { }在我的主ParentHomeComponent组件中,我想注入ChildHomeCOmponent的视图,如下所示:
<p>
Parent-home works!
</p>
<app-Child-home></app-Child-home>但是这会引发一个错误,说明ChildHomeComponent不是ParentModule的一部分(因为我不是直接导入它);
如何处理??
如果加载了模块,我的子主组件t将显示在父主组件下面。
建议??
发布于 2018-05-09 20:40:20
这不是懒惰加载的角度工作方式。
非延迟加载模块无法从延迟加载模块访问组件。
https://stackoverflow.com/questions/50261606
复制相似问题