I am trying to get the selected option index of a select using Angular. I am using Angular (4) and Ionic 3.
My template looks like below:
<ion-select [(ngModel)]="obj.city">
<ion-option *ngFor="let city of cities; let i = index;"
[value]="city" [selected]="i == 0">
{{city.name}}
</ion-option>
</ion-select>
I want the index of selected city to be accessed in Component code. Lets say, I want that index to be assigned to a variable selectedCityIndex in component.
My current code is pre selecting the first option as default. Solution should not break this functionality.
I am searching for a solution which do not include interating the array (i.e. no loop in JavaScript part). It should not use "indexOf" method or document's methods like "document.getElementById". I am not using jQuery.