I have below code which is working so far, but have small problem which I cannot figure it out. It's not updating (set the selected value into ion-select) ion-select after user chooses one option? Basically UI is not updating with selected value?
<ion-item>
<ion-label>Classifications</ion-label>
<ion-select [(ngModel)]="selectedItem" #item (change)="onChange(selectedItem)">
<ion-option *ngFor="#item of items" [value]="item">{{item}}</ion-option>
</ion-select>
</ion-item>
onChange(selectedItem) {
console.log('Selected item: '+selectedItem);
}
Out put properly displays as user select, any ideas what I'm missing here?
update
<ion-item>
<ion-label>Gender</ion-label>
<ion-select [(ngModel)]="gender">
<ion-option value="f" checked="true">Female</ion-option>
<ion-option value="m">Male</ion-option>
</ion-select>
</ion-item>
onChange(selectedItem)
being called?selectedItem
should already be updated by<ion-select [(ngModel)]="selectedItem"
.(change)="onChange(selectedItem)
shouldn't be necessary. – Günter Zöchbauer(change)="onChange(selectedItem)">
to(change)="onChange($event)">
or(change)="onChange(item.value)">
(I don't know what the property names of<ion-item>
actually are or what value it provides for the event. – Günter Zöchbauer(ngModelChange)="onChange($event)">
also callsonChange()
. – Günter Zöchbauer