I have a select list with the code -
<select (change)='onGroupChange($event)'>
<option *ngFor="let group of groups" value={{group.group_name}}>
{{group.group_name}}
</option>
</select>
Now I have a group name value saved as a different variable and I want to set that as the select list value if it matches any.
I have a select list with the code -
<select (change)='onGroupChange($event)'>
<option *ngFor="let group of groups" value={{group.group_name}}>
{{group.group_name}}
</option>
</select>
Now I have a group name value saved as a different variable and I want to set that as the select list value if it matches any.
Share Improve this question asked Sep 19, 2017 at 17:50 Vipul SharmaVipul Sharma 7983 gold badges11 silver badges25 bronze badges2 Answers
Reset to default 9<select (change)='onGroupChange($event)'>
<option *ngFor="let group of groups" value={{group.group_name}} [selected]="group.group_name==myVariable">
{{group.group_name}}
</option>
</select>
<select [(ngModel)]="selectedGroup" (ngModelChange)="onGroupChange($event)">
<option *ngFor="let group of groups" [value]="group.group_name">
{{group.group_name}}
</option>
</select>