angular – ng2-intl – 静态解析符号值时出错

前端之家收集整理的这篇文章主要介绍了angular – ng2-intl – 静态解析符号值时出错前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我意识到这是一个常见问题,但我无法弄清楚一个有效的实现.

我正在使用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]
    };   } }

解决方法

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

我得到了一个解决类似情况的解决方案,但不能保证.尽管它与角度/路由相同,方式为出口和forChild.将此配置添加到您的webpack的tsconfig中.

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"
}

猜你在找的Angularjs相关文章