【发布时间】:2017-11-18 22:54:24
【问题描述】:
我正在尝试为我的选择设置默认值,所以我尝试了
[selected]= "selected_choice == 'one'"
类似的东西
但这没有用。
人们说 [selected] 不再有效,所以我也尝试了 [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的内容,请参阅 stackoverflow.com/questions/44044746/… 和 stackoverflow.com/questions/44042797/… 了解更多信息。