在Angular中选择默认选择选项

时间:2018-04-14 05:30:16

标签: angular

input元素的以下代码中:

<select name="tshirtsize" [(ngModel)]="tshirtsize" class="form-control" 
        #tshirtRef="ngModel" required>
    <option *ngFor="let shirt of tShirtSize" [ngValue]="shirt"> 
        {{shirt.name}}
    </option>
</select>

如何在Angular中显示为用户选择的默认选项(例如,请选择选项)?

1 个答案:

答案 0 :(得分:2)

您可以添加类似

的内容
<select name="tshirtsize" [(ngModel)]="tshirtsize" class="form-control" #tshirtRef="ngModel" required>
    <option [ngValue]="undefined" disabled  selected> Please select one option </option>
    <option *ngFor="let shirt of tShirtSize" [ngValue]="shirt">{{shirt.name}}</option>
</select>