1

在 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),但我还没有找到如何对声明数组执行相同操作.

如何解决模块声明的问题?

4

1 回答 1

0

如何导出函数(返回 any[])和指向函数引用的声明指令。

于 2017-07-06T21:23:17.833 回答