我创建了以下文件来隔离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)
但它不再实际工作,不像我直接内联配置而不是功能。我做错了什么?
答案 0 :(得分:1)
尝试将您的功能更改为:
export function translateModuleConfig() {
return {
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [Http]
}
};
}
然后在app
模块中执行此操作:
TranslateModule.forRoot(translateModuleConfig());