![](/img/trans.png)
[英]How to get rid of Function calls are not supported in decorators in Angular aot compiling?
[英]angular2 AoT error Function calls are not supported
当我使用 angular2 AoT 时,出现错误:
Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 54:17 in the original .ts file), resolving symbol COMPILER_PROVIDERS in
在我的指令模块中,我有这样的代码:
import { COMPILER_PROVIDERS } from '@angular/compiler';
@NgModule({
/*imports ...*/
providers: [
COMPILER_PROVIDERS,
]
})
我知道我应该将COMPILER_PROVIDERS更改为导出函数,但是当我检查 @angular/compiler 的源代码时,我发现:
export declare const COMPILER_PROVIDERS: Array<any | Type<any> | {
[k: string]: any;
} | any[]>;
export declare class RuntimeCompilerFactory implements CompilerFactory {
private _defaultOptions;
constructor(defaultOptions: CompilerOptions[]);
createCompiler(options?: CompilerOptions[]): Compiler;
}
我不知道 COMPILER_PROVIDERS 是如何工作的,也不知道如何将它传输到我的模块中的导出函数。
解决方案是不再使用COMPILER_PROVIDERS
。 此外,您不需要在提供程序列表中包含JitCompiler
。
相反,使用来自“@angular/compiler”的JitCompilerFactory
。 它是不可注入的,所以只需像这样自己创建一个新实例:
private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();
其余的工作和以前一样,例如在这里遵循 Radim Kohler 的出色回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.