答案 0 :(得分:0)
在ngx-translate
Readme上写着:
注意:如果您仍然使用Angular< 4.3,请使用@ angular / http中的Http和http-loader@0.1.0。
那有什么区别?
在Angular> = 4.3.x中,您现在需要提供Http
,而不是向TranslateModule
提供HttpClient
:
app.module.ts:
import {HttpClient, HttpClientModule} from "@angular/common/http"; //<-- before import {HttpModule, Http} from "@angular/http";
...
export function HttpLoaderFactory(httpClient: HttpClient) { //<-- before Http
return new TranslateHttpLoader(httpClient, "i18n/", ".json");
}
@NgModule({
imports: [
...
HttpClientModule, //<-- before HttpModule
TranslateModule.forRoot({
loader: {
provide: TranslateLoader,
useFactory: HttpLoaderFactory,
deps: [HttpClient] //<-- before Http
}
})
],
...
})
我分叉并修复了Angular Demo(4.3.6):https://plnkr.co/edit/1VZdWdQvat3lxaXYVZs3?p=preview