【发布时间】:2017-07-07 05:23:17
【问题描述】:
在 Angular 2 中,只有当全局 javascript 变量设置为 true(调试布尔值)时,我才想在我的 ngModule 中声明一个指令。
这在使用 tsc 编译时有效:
declare let isDebug: boolean;
let dependencyArray : any[] = [];
if ('undefined' !== typeof isDebug && isDebug) {
dependencyArray.push(DebugDirective);
}
@NgModule({
declarations: [AppComponent].concat(dependencyArray),
imports: []
providers: [],
bootstrap: [AppComponent]
})
export class AppModule {}
然而,ngc 编译器(AOT 编译)似乎不接受模块文件中的函数调用。 ngc 抛出以下错误。
静态解析符号值时遇到错误。不支持函数调用。考虑将函数或 lambda 替换为对导出函数的引用
我找到了各种线程来解释如何将工厂与提供者的导出函数一起使用(例如 https://github.com/angular/angular/issues/11262),但我还没有找到如何为声明数组做同样的事情。
如何解决模块声明的问题?
【问题讨论】:
标签: angular angular2-aot