【问题标题】:ng2-intl - Error encountered resolving symbol values staticallyng2-intl - 静态解析符号值时遇到错误
【发布时间】:2017-11-08 09:08:36
【问题描述】:

我意识到这是一个常见问题,但我无法找到可行的实现方式。

我正在使用 Angular 4.2.6 和 ng2-intl 2.0.0-rc.3。

我尝试了以下方法,但仍然无法正常工作:

export function intlFactory(http:Http) {
  return new IntlStaticLoader(http, '../../locale', '.json');
}

@NgModule({
  imports: [
    IntlModule.forRoot({ 
      provide: IntlLoader,
      useFactory: intlFactory,
      deps: [Http]
    })
  ]
});

例外是:

不支持函数调用,请考虑将函数或 lambda 替换为对导出函数的引用

我查看了源代码,它做到了(关于如何在 fork 上更改它以使其工作的任何想法?)

export class IntlModule {   
    static forRoot(providedLoader: any = {
      provide: IntlLoader,
      useFactory: i18nLoaderFactory,
      deps: [Http]   }): ModuleWithProviders {
    return {
      ngModule: IntlModule,
      providers: [providedLoader, IntlService]
    };   } }

【问题讨论】:

    标签: angular typescript internationalization angular2-modules


    【解决方案1】:

    我以为你更新到新的ngc 并且它改变了优化然后forRoot 无法回调ngModule 注释。

    我得到了解决类似情况的一种解决方案,但不能保证。尽管它与angular/route 到插座forRootforChild 的方式相同。将此配置添加到您的tsconfig 为您的webpack

    tsconfig.yourbuild.ts.

    "compilerOptions": {
      "declaration": true,
      "stripInternal": true,
      "moduleResolution": "node",
      "module": "es2015",
      "target": "es5",
      "lib": [
        "es2015",
        "es2017",
        "dom"
      ],
      "skipLibCheck": true,
      "types": [],
      "experimentalDecorators": true,
      "emitDecoratorMetadata": true,
      "sourceMap": true,
      "inlineSources": true,
      "baseUrl": "./tmp", //set what you base on.
      "rootDir": "./tmp", //set what you base on.
      "outDir": "dist/"
    },
    "angularCompilerOptions": {
        "annotationsAs": "decorators",
        "annotateForClosureCompiler": false,
        "strictMetadataEmit": false,
        "skipTemplateCodegen": true,
        "flatModuleOutFile": "router.js",
        "flatModuleId": "@angular/router"
    }
    

    【讨论】:

    • 对不起,这对我不起作用。您认为哪些具体的行会有所帮助?
    猜你喜欢
    • 1970-01-01
    • 2018-01-03
    • 2017-09-06
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-04
    • 2017-06-09
    相关资源
    最近更新 更多