Reputation: 153
I have made an select with diff options in angular 2
<select [(ngModel)]="LineBusinnes" (ngModelChange)="onChange($event)" id="selLineOfBusiness" class="form-control">
<option [ngValue]="i.id" *ngFor="let i of lineBusiness" >{{i.name}}</option>
</select>
Where line businnes is an array.I would like to be selected by default the first option.
How can I do that?
Thanks!
Upvotes: 1
Views: 9042
Reputation: 8992
You can get index in ngFor
and set selected
attribute based on it.
<option [ngValue]="i.id" *ngFor="let i of lineBusiness; let idx = index" [attr.selected]="idx == 1">{{i.name}}</option>
Upvotes: 1