Having a dropdown with option populated using ngFor in angular 2 code. I need any particular option at any given index to be selected by default.
I have used [attr.selected]="i == 0" ,but it selects last option instead first one.
Here is My code
<select id="roles" required formControlName="userRole">
<option *ngFor="let roles of URoles;let i = index" [attr.selected]="(i==0)" [value]="roles._id">{{ roles.name }}</option>
</select>
What could be the problem ? Why first option not selected ?