3

尝试使用以下命令编译我的 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...错误消失。

正如错误所暗示的那样,如何用导出的函数替换它?

4

2 回答 2

4

我有一些运气这样做:

export function translateStaticLoaderFactory(http: Http) {
  return new TranslateStaticLoader(http, 'app/languages', '.json');
}

@NgModule({
imports: [
    CommonModule,
    TranslateModule.forRoot({ 
        provide: TranslateLoader,
        useFactory: translateStaticLoaderFactory,
        deps: [Http]
    })
],

于 2016-09-28T14:41:55.293 回答
0

您必须首先将 ng2-translate 更新为 >5.0.0。我在 ~2.5.0 版本上遇到了同样的问题,导出的功能没有帮助。

所以你的步骤:

  1. 更新版本 >5.0.0
  2. 艾萨克提到的导出功能:

导出函数 translateStaticLoaderFactory(http: Http) { return new TranslateStaticLoader(http, 'app/languages', '.json'); }

@NgModule({ 导入:[CommonModule, TranslateModule.forRoot({ 提供:TranslateLoader, useFactory: translateStaticLoaderFactory, deps: [Http] }) ],

于 2017-02-02T10:06:00.787 回答