我試圖設置默認值我的選擇,所以我嘗試Angular2 [選擇]無法設置默認值?
[selected]= "selected_choice == 'one'"
像這樣
但這並沒有工作。
人們說[選擇]不再工作,所以我也試過[attr.selected],但沒有工作以及..
這是我的一個選擇標籤
<select (change)="passValue3()" formControlName="school" class="form-control" required [(ngModel)]="selected_student" class="selectionbox">
<option *ngIf="selected_student == undefined">학년 선택</option>
<option *ngFor="let gradetype of gradeTypes" [ngValue]="gradetype" [attr.selected] = "gradetype.gradeType === 'Middle'">{{gradetype.gradeName}}</option>
</select>
整個代碼我如何設置選擇的默認選項?
這是基於綁定到'option'什麼,見https://stackoverflow.com/questions/44044746/selected-of-select-doesnt-work-as-excepted-in-angular2,也htt ps://stackoverflow.com/questions/44042797/angular-2-set-selected-on-a-select-option-dropdown/44043801#44043801欲瞭解更多信息。 – Pengyy