我有这个代码,但它并没有让我选择我标记的选项。有谁知道为什么?
<select class="choose" [(ngModel)]="selectInfo">
<option value="" selected >Selecciona Opción</option>
<option *ngFor="let item of items" [value]="item.nombre">{{item.nombre}}
</option>
</select>
我也试过
选择=真;
[attr.selected]=真
但它不起作用。
由于您使用的是
ngModel
,因此您可以在组件上分配默认值。证明:并且将选择具有该值(空字符串)的选项。
你可以在这个 StackBlitz中看到它。