【发布时间】:2020-03-10 12:53:47
【问题描述】:
虽然固定数组有效?
我想使用这个从路由中提取组件的工具:
function* getRoutesComponents(routes: Routes) {
for (const route of routes) {
if (route.component) {
yield route.component;
if (route.children) {
yield* getRoutesComponents(route.children);
}
}
}
}
@NgModule({
imports: [SharedModule, RouterModule.forChild(ROUTES)],
declarations: getRoutesComponents(ROUTES)
})
export class ProductModule {}
所以我可以避免在声明属性中丢失组件声明。声明中缺少组件会导致错误:NG8002: Can't bind to 'ngModel' since it isn't a known property of 'input'
【问题讨论】:
-
我已经尝试在stackblitz.com/edit/… 的示例应用程序中复制您的场景,它只能正常工作..
childcomponent和appcomponent被推入a并已加载.. -
@ManirajMurugan 对您的示例作品感兴趣。我正在使用这个例子:github.com/DeborahK/Angular-Routing。也许该项目上有一些角度或打字稿设置使角度或打字稿静态读取 NgModule
标签: angular