在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中显示为用户选择的默认选项(例如,请选择选项)?
答案 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>