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.
<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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With