2016-11-16 37 views
3

當我使用angular2 AOT,我得到一個錯誤:angular2 AOT誤差函數調用不suppoted

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是如何工作的,我不知道如何將它傳輸到模塊中的導出函數。 如果有人能幫助我,我將不勝感激!

+0

有同樣的問題,還沒有找到解決方案... – Sebastian

回答

8

解決方案是不再使用COMPILER_PROVIDERS。此外,您不需要在提供商列表中包含JitCompiler

改爲使用「@ angular/compiler」中的JitCompilerFactory。它不是注射的,所以就是創建一個它自己這樣一個新的實例:

private compiler: Compiler = new JitCompilerFactory([{useDebug: false, useJit: true}]).createCompiler(); 

其餘像以前一樣工作,例如以下拉迪姆科勒的出色答卷here

+0

謝謝很多塞巴斯蒂安,這真的幫助我! – maxbellec

+2

任何人都有使用AOT示例工作的JitCompiletFactory?當我使用它時,我總是得到DynamicHtmlModule的No NgModule元數據 – user2771738

+2

只是想補充一點,顯示的編譯器來自@ angular/core,而不是像以前的JitCompiler和工廠那樣的@ angular /編譯器。花了我一段時間找到它。 – Tarmo

相關問題