In my Angular app, I have a <select> with a list of <option>s whose values are bound to objects.
I'm trying to get the last value selected using:
<select (change)="onSelect($event)">
<option *ngFor="let option of myOptions;" [ngValue]="option"> {{ option.name }} </option>
</select>
onSelect(event: Event) {
console.log(event);
}
So my options are bound to objects (myOptions is an array of objects).
This works fine and the {{ option.name }} (that is a string) is correctly displayed.
The problem is that the event.target.value in my onSelect will be a string like "1: Object", "2: Object", etc...
If I use [value] instead of [ngValue] the problem would be slightly different and the event.target.value would this time be the "[object Object]" string.
How can I get the real selected object option when emitting the (change) event?