Reputation: 194
I have a Service List and i want to set the Selected option as the first Service of my list. I found this code and for other instances it works but not for this. And i dont understand why,
public Servicelist: Array<ServiceModel> = []
// I fill it via a webservice where i return a JSON
this.Servicelist = await this.service.GetServicelist()
<select [(ngModel)]="SelectedService">
<option *ngFor="let s of Servicelist; let i = index"
[value]="s.id"
[selected]="i == 0">
{{s.name}}
</option>
</select>
Upvotes: 0
Views: 27
Reputation: 104795
You need to set your ngModel
variable to the first id in the list
this.SelectedService = this.Servicelist[0].id
Upvotes: 1