TranslateModule和TranslationPipe在Angular2 Final中不再起作用 [英] TranslateModule and TranslationPipe is not working anymore in Angular2 Final

查看:63
本文介绍了TranslateModule和TranslationPipe在Angular2 Final中不再起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

import {
  TranslatePipe,
  TranslateModule,
  TranslateService,
  TranslateLoader,
  TranslateStaticLoader,
  MissingTranslationHandler
} from "ng2-translate/ng2-translate";

@NgModule({
  declarations: [
    MyApp
  ],
  imports: [
        IonicModule.forRoot(MyApp, {}),
        HttpModule,
         TranslateModule.forRoot({
             provide: TranslateLoader,
             useFactory: (http: Http) => new TranslateStaticLoader(http, "../../www/assets/i18n", ".json"),
             deps: [Http]
         }),
        StoreModule.provideStore(rootReducer)
    ]..

错误

以上不适用于ng2-final.我得到:

Error

Above does not work with ng2-final. I get:

03:26:44]  ngc: Error: 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 98:25 in the original .ts file), resolving symbol AppModule in /Users/me/devel/mega-project/.tmp/app/app.module.ts

预期的行为

在RC4上,实现应该像以前一样工作,例如:

Expected behaviour

Implementation should work like before on RC4, e.g.:

 <div style="text-transform:none">{{ "§GLOBAL.PHONE_CALL_FREE" | translate }}</div>

推荐答案

1.).拉取3.1.0的ng-translate或更高版本,以实现ng2 AoT兼容性和元信息.

1.) Pull 3.1.0 of ng-translate or later where they implemented ng2 AoT compatibility and meta information.

2.)然后使用

import {TranslateModule, TranslateStaticLoader} from "ng2-translate/ng2-translate";
import {TranslateLoader} from "ng2-translate";

export function translateLoaderFactory(http: any) {
  return new TranslateStaticLoader(http, './assets/i18n', '.json');
}
@NgModule({
imports: [
    IonicModule.forRoot(MyApp),
    HttpModule,
    TranslateModule.forRoot({
    provide: TranslateLoader,
       useFactory: translateLoaderFactory,
       deps: [Http]
   }),

3.).如果不起作用,请继续执行该线程中的其他步骤:

3.) If not working, follow up on other steps from this thread:

https://github.com/ocombe/ng2-translate/issues/218

这篇关于TranslateModule和TranslationPipe在Angular2 Final中不再起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆