I am trying to trigger a change event everytime I change my option in an ion-select component. The problem is that the change event is triggered when I press the OK button in the popover of the ion-select button. I want to trigger the change event EVERYTIME I select an option.
My initial goal is to select an option and close immediately the popover.
P.S. Please do not propose interface property because I want to keep the design of ion-alert.
Any ideas?
My code:
In my html file:
<ion-item>
<ion-select value="-1" (ionChange)="triggerEvent()">
<ion-select-option value="-1">All</ion-select-option>
<ion-select-option value="a">A</ion-select-option>
<ion-select-option value="b">B</ion-select-option>
<ion-select-option value="c">C</ion-select-option>
</ion-select>
</ion-item>
In my ts file:
triggerEvent() {
console.log('event trigger');
}
There are two ways to achieve that:
Solution 1
The one way that I would suggest to do that so easily is to use an
interface="popover"like this and the output like this:and the result will look like this:
Soultion 2
If you want to stick with the same design you can try to add an event listener when user click on the
ion-select-optionand close theion-selectmanually it will take some time to implement correctly but it's possible to do that also.