Angular ngx-translate中英文切换

1.安装包

npm install @ngx-translate/core --save 
npm install @ngx-translate/http-loader --save

2.根模块app.module.ts 引入

import { HttpClientModule, HttpClient } from '@angular/common/http';
import { TranslateModule, TranslateLoader } from '@ngx-translate/core';
import { TranslateHttpLoader } from '@ngx-translate/http-loader';
export function createTranslateLoader(http: HttpClient) {
  return new TranslateHttpLoader(http, './assets/i18n/', '.json');
}

  imports: [
    HttpClientModule,
    TranslateModule.forRoot({
      loader: {
          provide: TranslateLoader,
          useFactory: createTranslateLoader,
          deps: [HttpClient]
      }
    })
  ],

3.在有需要的模块引入 TranslateModule

 

上一篇:Idea 插件使用测评


下一篇:JS日期时间格式化yyyy-MM-dd