I have this code, but it does not leave me as selected the option that I have marked. Does anyone know why?
<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>
I have also tried with
selected = true;
[attr.selected]=true
But it does not work.
Since you're using
ngModel
, you can assign the default value on the component. Proof:and the option that has that value (an empty string) will be selected.
You can see it in this StackBlitz .