第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

在下拉菜單中保存最后選擇的選項(xiàng)

在下拉菜單中保存最后選擇的選項(xiàng)

炎炎設(shè)計(jì) 2021-12-23 16:53:10
我是 angular 的新手,我正在嘗試保存選擇選項(xiàng)標(biāo)簽,但是語言已成功保存,即使我選擇阿拉伯語,選擇選項(xiàng)默認(rèn)顯示英語,當(dāng)頁面刷新時(shí)它會(huì)恢復(fù)為英語,如果您能幫助我實(shí)現(xiàn)這一目標(biāo),我將不勝感激頁腳.component.html<div class="form-group">   <select (change)="switchLanguage($event)" [ngModel]="lang" style="background-color:        #b3cee5;" class="form-control customized-dropdown alignleft">       <option id="myLanguage" *ngFor="let item of Languages">{{item}}</option>   </select></div>頁腳.component.tsdirectionEn: any;directionAr: anylanguage;userLang;localsettings: LocalSettingsService;Languages : any = ['English', 'Arabic'];lang;constructor(private translate: TranslateService) {  translate.setDefaultLang('en');}switchLanguage(event) {if(event.target.value == 'English'){  this.language = 'en'  this.lang = event.target.value;  this.ChangeToEnglish()} else if(event.target.value == 'Arabic'){  this.language = 'ar'  this.lang = event.target.value;  this.ChangeToArabic();}this.translate.use(this.language);localStorage.setItem('lang', this.lang)localStorage.setItem('language', this.language);}ChangeToEnglish(){  document.querySelector('body')  .setAttribute('style', 'direction: ltr; text-align: left; ');}ChangeToArabic(){  document.querySelector('body')   .setAttribute('style', 'direction: rtl; text-align: right;');}ngOnInit() {  var language = localStorage.getItem('language')  var lang = localStorage.getItem('lang')if(language === 'ar' && lang === "Arabic"){  this.translate.use('ar');  this.ChangeToArabic();}else if(language === 'en' && lang === "English"){  this.translate.use('en');  this.ChangeToEnglish()}}
查看完整描述

2 回答

?
牧羊人nacy

TA貢獻(xiàn)1862條經(jīng)驗(yàn) 獲得超7個(gè)贊

試試這個(gè)


constructor(private translate: TranslateService) {

  translate.setDefaultLang(localStorage.getItem('language') ? localStorage.getItem('language') : 'en');

}


查看完整回答
反對(duì) 回復(fù) 2021-12-23
?
尚方寶劍之說

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>


查看完整回答
反對(duì) 回復(fù) 2021-12-23
  • 2 回答
  • 0 關(guān)注
  • 190 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)