我有一个由多个不同客户使用的角度应用程序,我目前正在从角度4更新为角度6.客户有自己不同的扩展,因此在角度4中我为每个客户创建了一个模块(设置自定义)然后我为每个客户创建了一个environment.CUSTOMER_NAME.ts
文件,内容如下:
export const environment: Environment = {
extraModules: [MODULE_FOR_THIS_CUSTOMER]
};
然后在我使用的主要模块中:
@NgModule({
imports: (<Array<Type<any> | ModuleWithProviders | any[]>>[
BrowserModule,
FormsModule,
/* .. */
].concat(environment.extraModules)),
/* .. */
})
export class AppModule { }
这很有效。运行ng build --env=SOME_CUSTOMER
构建整个应用程序,包括该特定客户的模块。
现在我升级到了角度6,我收到了错误:
ERROR in : 'router-outlet' is not a known element:
1. If 'router-outlet' is an Angular component, then verify that it is part of this module.
2. If 'router-outlet' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<router-outlet></router-outlet>")
经过一天白发并考虑辞掉工作并成为公交车司机后,我终于想通了,我的concat
- 命令似乎是问题的根源。至少它与选项
"aot": true,
"buildOptimizer": true,
<{1>}文件中的。如果我把它们都设置为假,那么一切都运行正常,即使是我的旧结构。删除angular.json
命令也可以解决问题。
当然,我真的不想关闭这些选项,那么只有在某个配置处于活动状态时,我还能做什么才能包含模块?
答案 0 :(得分:1)
它说:
ERROR in : 'router-outlet' is not a known element:
我想你可能在你的客户模块中使用路由器插座。您需要确保在模块中导入路由器模块。
答案 1 :(得分:0)
虽然concat
调用不再可行,但在使用自版本2.1以来TypeScript也支持的the spread-operator ...
时它可以正常工作:
@NgModule({
imports: [
/* .. */
...environment.extraModules
]
})