In Angular 1.x, you could bind ngModel to a model for a select control:
<select ng-model="selectedPerson"
ng-options="person as person.name for person in people">
</select>
When an option is selected, the selectedPerson
model will point to the person
model that the user selected.
Is there a way to do the same thing in Angular2?
I've tried the following with no luck:
<select [(ngModel)] = "selectedPerson">
<option *ngFor="#person of people"> {{ person.name }}</option>
</select>
I've also tried:
<select [(ngModel)] = "selectedPerson">
<option *ngFor="#person of people" [value]="person"> {{ person.name }}</option>
</select>
In the first attempt, selectedPerson
model references person.name
rather than the person
object. And in the second attempt, it is referencing an object, which doesn't appear to be a JSON object.
Any ideas what I am doing wrong? Is this even possible?