TranslateModule配置不起作用

时间:2017-05-14 14:02:55

标签: angular typescript angular-module ngx-translate

我创建了以下文件来隔离ngx-translate配置:



import {
  Http
} from '@angular/http';
import {
  TranslateHttpLoader
} from '@ngx-translate/http-loader';
import {
  TranslateLoader,
  TranslateModuleConfig
} from '@ngx-translate/core';

// AoT requires an exported function for factories
export function HttpLoaderFactory(http: Http) {
  return new TranslateHttpLoader(http);
}

export function translateModuleConfig(): TranslateModuleConfig {
  return {
    loader: {
      provide: TranslateLoader,
      useFactory: HttpLoaderFactory,
      deps: [Http]
    }
  };
}




然后,我只是在我的应用模块imports部分中使用以下内容:

TranslateModule.forRoot(translateModuleConfig)

但它不再实际工作,不像我直接内联配置而不是功能。我做错了什么?

1 个答案:

答案 0 :(得分:1)

尝试将您的功能更改为:

export function translateModuleConfig() {
  return {
    loader: {
      provide: TranslateLoader,
      useFactory: HttpLoaderFactory,
      deps: [Http]
    }
  };
}

然后在app模块中执行此操作:

TranslateModule.forRoot(translateModuleConfig());