2 回答

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊
試試這個(gè)
constructor(private translate: TranslateService) {
translate.setDefaultLang(localStorage.getItem('language') ? localStorage.getItem('language') : 'en');
}

TA貢獻(xiàn)1788條經(jīng)驗(yàn) 獲得超4個(gè)贊
我終于找到了解決方案,您只需為每個(gè)語句添加一個(gè)變量,如下所示:
頁腳.component.ts
ngOnInit() {
var language = localStorage.getItem('language')
var lang = localStorage.getItem('lang')
if(language === 'ar' && lang === "Arabic"){
this.translate.use('ar');
this.ChangeToArabic();
this.bind = "Arabic";
}
else if(language === 'en' && lang === "English"){
this.translate.use('en');
this.ChangeToEnglish()
this.bind = "English";
}
頁腳.component.html
只需將 [(ngModel)]="bind" 添加到選擇標(biāo)簽
<select (change)="switchLanguage($event)" [(ngModel)]="bind"
style="background-color: #b3cee5;" class="form-control>
<option id="myLanguage" *ngFor="let item of Languages">{{item}}</option>
</select>
添加回答
舉報(bào)