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在这里的出色回答。
相关文章:
- javascript函数调用不起作用
- 函数调用不起作用
- 为什么这两个函数调用不相等
- 为什么这个javascript函数调用不起作用
- jQuery函数调用不起作用
- JQuery .ajax() 函数调用不起作用,但成功方法运行
- JS简单函数调用不起作用
- Javascript函数调用不起作用
- Chrome扩展->ExecuteScript:函数调用不'工作
- 函数未定义..我的函数调用不起作用
- 动态函数调用不变
- Javascript函数调用不起作用
- Javascript函数调用不可用
- javascript的函数调用不起作用
- 页面加载后的JavaScript函数调用不工作
- 设置innerHTML的函数调用不工作-给出未定义
- 函数调用不起作用
- 动态添加的元素函数调用不工作
- 从玉模板Javascript函数调用不工作
- Javascript对象函数调用不起作用