簡體   English   中英

angular2 AoT 錯誤不支持函數調用

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM