尝试使用以下命令编译RC6应用程序时:
ngc -p C:\Path\To\Project
(当我运行命令时,我被放在C:\Path\To\Project\node_modules\.bin
内)
我收到以下错误:
Error encountered resolving symbol values statically. Function calls are not supported. Consider replacing the function or lambda with a reference to an exported function (position 20:25 in the original .ts file), resolving symbol CoreModule in C:/Path/To/Project/app/modules/core/core.module.ts
这是抱怨的:
@NgModule({
imports: [
CommonModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: (http: Http) => new TranslateStaticLoader(http, 'app/languages', '.json'),
deps: [Http]
})
],
如果我删除TranslateModule.forRoot...
,则错误消失。
如何使用导出的函数替换它,因为错误意味着什么?
答案 0 :(得分:4)
我有幸运气这样做:
export function translateStaticLoaderFactory(http: Http) {
return new TranslateStaticLoader(http, 'app/languages', '.json');
}
@NgModule({
imports: [
CommonModule,
TranslateModule.forRoot({
provide: TranslateLoader,
useFactory: translateStaticLoaderFactory,
deps: [Http]
})
],

答案 1 :(得分:0)
首先必须将ng2-translate更新为> 5.0.0。 我在版本~2.5.0上遇到了同样的问题,导出的函数也无济于事。
所以你的步骤:
导出函数translateStaticLoaderFactory(http:Http){ 返回新的TranslateStaticLoader(http,' app / languages',' .json'); }
@NgModule({ 进口:[ CommonModule, TranslateModule.forRoot({ 提供:TranslateLoader, useFactory:translateStaticLoaderFactory, deps:[Http] }) ],