Reputation: 31
In the following code for an input
element:
<select name="tshirtsize" [(ngModel)]="tshirtsize" class="form-control"
#tshirtRef="ngModel" required>
<option *ngFor="let shirt of tShirtSize" [ngValue]="shirt">
{{shirt.name}}
</option>
</select>
How to show default option selected for user (ex. please select option) in Angular?
Upvotes: 1
Views: 102
Reputation: 222720
You can add something like
<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>
Upvotes: 2