Reputation: 2515
I am trying to get the index value of the selected item
from dropdown.
In order to do that, this is the code I am trying:
<ion-select okText="Okay" cancelText="Dismiss" [(ngModel)]="dropdown1" (ionChange)="onSelectChange($event)" >
<ion-select-option *ngFor="let list of goalList;let i=index;" (ionSelect)=" myfun(); myIndex = i" value="{{list.docid}}">
{{list.personalEmail}}
</ion-select-option>
</ion-select>
I was never getting myIndex
number, so I tested by adding a function
. The function is never invoked.
I searched and found this solution but it was working on ion-option
for Ionic 3, but this is not working on ion-select-option
in Ionic 4.
Upvotes: 0
Views: 871
Reputation: 432
One option is to set the ion-select-option
value as an object as below with the docid and index, this way the object with the docid and index will bind to the ngModel and will be accessible on the ionChange
event.detail.value
<ion-select okText="Okay" cancelText="Dismiss" [(ngModel)]="dropdown1" (ionChange)="onSelectChange($event)">
<ion-select-option *ngFor="let list of goalList;let i=index;" [value]="{docid:list.docid,index:i}">
{{list.personalEmail}}
</ion-select-option>
</ion-select>
Upvotes: 1