2 回答
TA贡献1862条经验 获得超7个赞
试试这个
constructor(private translate: TranslateService) {
translate.setDefaultLang(localStorage.getItem('language') ? localStorage.getItem('language') : 'en');
}
TA贡献1788条经验 获得超4个赞
我终于找到了解决方案,您只需为每个语句添加一个变量,如下所示:
页脚.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" 添加到选择标签
<select (change)="switchLanguage($event)" [(ngModel)]="bind"
style="background-color: #b3cee5;" class="form-control>
<option id="myLanguage" *ngFor="let item of Languages">{{item}}</option>
</select>
添加回答
举报