ngx-translate不能在ng-bootstrap模式下工作

时间:2017-08-30 09:43:37

标签: angular ng-bootstrap ngx-translate

ngx-translate的{​​{1}}管道在translate的{​​{3}}内无效。

ng-bootstrap

modal

1 个答案:

答案 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