簡體   English   中英

無法使用角度在 html 選擇中重置第一個項目

[英]Can't get 1st item to reset in a html select using angular

當我最初在模態窗口中打開它時,我的下拉菜單工作正常。 如果我將選擇更改為某個選擇下拉值,然后關閉模態並重新打開,它會保持不變。 它不會將其重置為“未選擇”

這是我在做什么

 // in my ts file when I open the modal this.geModal.state = '';
 <select class="form-control" name="prState"> <option [selected]="geModal.state == ''">None selected</option> <option *ngFor="let state of stateList" [value]="state.code" [selected]="geModal.state == state.code"> {{state.name}} </option> </select>

您不應將[selected][ngModel]混合使用,不要為state使用默認值並為默認選項設置value="undefined"

<select class="form-control" [(ngModel)]="geModal.state" name="prState">
  <option value="undefined">None selected</option>
  <option *ngFor="let state of stateList" [value]="state.code">{{state.name}}</option>
</select>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM