angular2 ngModel/ngValue select option object - equality across different instances
Per @Klinki
Currently there is no simple solution in angular 2, but in angular 4 this is already addressed since beta 6 using
compareWith
- see https://github.com/angular/angular/pull/13349
To illustrate the usage for the proposed case (see plunk):
<div *ngFor='let a of activePerson.hobbyList ; let i=index;'>
<label for='personHobbies'>Hobby:</label>
<select id='personHobbies' class='form-control'
name='personHobbies' [(ngModel)]='activePerson.hobbyList[i]'
[compareWith]='customCompareHobby'>
<option *ngFor='let h of hobbyListSelect;' [ngValue]='h'>{{h.name}}</option>
</select>
</div>
...
customCompareHobby(o1: Hobby, o2: Hobby) {
return o1.id == o2.id;
}
Currently there is no simple solution in angular 2, but in angular 4 this is already addressed since beta 6 - see https://github.com/angular/angular/pull/13349