【发布时间】:2017-10-09 23:40:03
【问题描述】:
我目前正在开发 Angular2 的一个应用程序。我有 3 个功能模块,其中包含其他子功能模块。 我想将功能 1 的子功能模块加载到功能 2 的子功能模块中,反之亦然。下面是示例代码。
action-routing.module.ts
const routes: Routes = [
{
path: '',
component: ActionComponent,
children: [
{
path: ':id',
loadChildren: 'app/action/action-detail/action-detail.module#ActionDetailModule'
}
]
}
];
action-detail-routing.module.ts
const routes: Routes = [
{
path: '',
component: ActionDetailComponent,
},
{
path: 'topic-detail/:id',
loadChildren: 'app/topic/decision-topic-detail/decision-topic-detail.module#DecisionTopicDetailModule',
}
]
topic-routing.module.ts
const routes: Routes = [
{
path: '',
component: TopicComponent,
children: [
{
path: ':id',
loadChildren: 'app/topic/decision-topic-detail/decision-topic-detail.module#DecisionTopicDetailModule'
}
]
}
];
decision-topic-detail-routing.module.ts
const routes: Routes = [
{
path: '',
component: DecisionTopicDetailComponent,
},
{
path: 'action-detail/:id',
loadChildren: 'app/action/action-detail/action-detail.module#ActionDetailModule'
}
]
这会创建循环依赖并在编译时抛出 ERROR in Maximum call stack size exceeded 错误。
有什么办法可以解决这个错误。我知道一种方法是自行加载整个功能模块,但这是不可行的情况。
提前致谢。
【问题讨论】:
-
这是 Angular CLI 中的一个错误。 github.com/angular/angular-cli/issues/6309
标签: angular typescript webpack angular-cli circular-dependency