Here is a plunker:
<select [(ngModel)]="selectedValue">
<option
*ngFor="let item of items"
[attr.selected]="item.Id == selectedValue.Id ? '' : null"
[ngValue]="item" >
{{item.Text}}
</option>
</select>
export class App {
selectedValue: DataItem = {Id: 2, Text: 'two'};
items: DataItem[] = [{Id: 1, Text: 'one'}, {Id: 2, Text: 'two'}, {Id: 3, Text: 'three'}]]; }
export class DataItem{
Id: number;
Text: string;
}
Tried many suggestions from various google and stackoverflow answers, but could not get it working. Anyone has a solution? I'm not interested in a solution which suggests NOT to use ngModel or handle change events.