ngx翻译Angular 5

时间:2018-08-10 11:25:01

标签: javascript angular ionic3 ngx-translate

当我在settings.ts(页面)中更改语言并在同一页面中检查currentLanguage时,它会正确更改语言并显示它。

但是当我在app.component.ts中执行相同的操作时,即使我更改了10次,CurrentLanguage也不会更改。

这是代码。用于语言更改的按钮位于settings.html中。

settings.ts

import { TranslateService } from '@ngx-translate/core';

constructor(private translate: TranslateService){
   //code...
}
changeLang(lang){
  this.translate.use("en");
  console.log("Switched to ", this.translate.currentLang);
  this.translate.use("ru");
  console.log("Switched to ", this.translate.currentLang);
} 

app.component.ts

import { TranslateService } from '@ngx-translate/core';


constructor(private translate: TranslateService){
   //code...
}

this.translate.use("ru");
  console.log("it is   ", this.translate.currentLang);
this.translate.use("en");
  console.log("it is   ", this.translate.currentLang);
this.translate.use("ru");
  console.log("it is   ", this.translate.currentLang);

settings.ts的输出

Switched to  en 
Switched to  ru

app.component.ts的输出

it is    to ru
it is    to ru
it is    to ru

0 个答案:

没有答案