gpt4 book ai didi

javascript - Angular:延迟加载子模块并将其主要组件注入(inject)Parent home组件的View

转载 作者:行者123 更新时间:2023-11-30 06:50:54 25 4
gpt4 key购买 nike

我有一个父模块,我在其中延迟加载一个子模块

如您所见,我没有直接导入我的子模块,而是在路由文件下延迟加载它:

父模块:

@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 我想注入(inject)我的 ChildHomeCOmponent 的 View ,像这样:

<p>
Parent-home works!
</p>
<app-Child-home></app-Child-home>

but this throws an error telling that the ChildHomeComponent isn't part of the ParentModule (as i'm not importing it directly) ;

如何处理??

我希望如果加载了模块,我的child home component 会显示在parent home component

建议??

最佳答案

这不是 Angular 中延迟加载的工作方式。

非延迟加载模块无法访问延迟加载模块中的组件。

关于javascript - Angular:延迟加载子模块并将其主要组件注入(inject)Parent home组件的View,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50261606/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com