当我使用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的出色回答here。