[英]angular2 AoT error Function calls are not supported
When I use angular2 AoT, I get an error:当我使用 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
and in my Directive Module, I have code like this:在我的指令模块中,我有这样的代码:
import { COMPILER_PROVIDERS } from '@angular/compiler';
@NgModule({
/*imports ...*/
providers: [
COMPILER_PROVIDERS,
]
})
I understand that I should change the COMPILER_PROVIDERS to an exported function, But when I check the source code of @angular/compiler, I find this:我知道我应该将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;
}
I don't know how the COMPILER_PROVIDERS works, and I don't know how to transfer it to a exported function in my module.我不知道 COMPILER_PROVIDERS 是如何工作的,也不知道如何将它传输到我的模块中的导出函数。
The solution is to not use COMPILER_PROVIDERS
any more.解决方案是不再使用
COMPILER_PROVIDERS
。 Also, you do not need to include JitCompiler
in your list of providers.此外,您不需要在提供程序列表中包含
JitCompiler
。
Instead, use JitCompilerFactory
from "@angular/compiler".相反,使用来自“@angular/compiler”的
JitCompilerFactory
。 It is not injectable, so just create a new instance of it yourself like this:它是不可注入的,所以只需像这样自己创建一个新实例:
private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler();
The rest works as before, for example following Radim Kohler's excellent answer here .其余的工作和以前一样,例如在这里遵循 Radim Kohler 的出色回答。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.