Sometimes, we want to set dropdown options default value with Angular.
In this article, we’ll look at how to set dropdown options default value with Angular.
How to set dropdown options default value with Angular?
To set dropdown options default value with Angular, we can add the selected
attribute to the default option in the select.
For instance, we write
<select name="types" id="types" [(ngModel)]="model.type" #type="ngModel">
<option class="" disabled selected value="undefined">Select an Option</option>
<option *ngFor="let item of courseTypes; let x = index" [ngValue]="type.id">
{{ item.name }}
</option>
</select>
to make the first option the default one by adding the selected
attribute to the option.
Conclusion
To set dropdown options default value with Angular, we can add the selected
attribute to the default option in the select.