Ionic 2 toggle component binding and events


Hello, I’m a bit stumped about this and I’d appreciate some help.

With this in my html:

<ion-toggle [(ngModel)]="AutoRefresh" (change)="onChange()" item-right></ion-toggle>

and this boolean in my js;

this.AutoRefresh = this._currentUserData.getAutoRefresh();

I was expecting this:

onChange() { console.log(this.AutoRefresh); }

To show true and false. It does not show anything. When I use the click event, true and false are showing up but there is a lag i.e. it is showing the last value of the boolean rather than the updated value from the click event.

I’m new to Ionic 2 so sorry if there’s a total misunderstanding built into this question!




which version of ionic2 are you using?

In the beta8 version, the (change) event was replaced by (ionChange)… but for me (ionChange) doesnt work correctly in the beta9


I’m on beta8 at the moment. I’ve tried (ionchange) as well. Not doing what I expected.

Does the code look correct to you? Am I right in assuming that the ngmodel should be updating the variable as soon as it changes?


Actually you’re right, ionChange was the key, I must have had ionchange instead when I tried it before. Thanks for the tip about beta9.



I dont know if the problem with the beta9 is happening with everyone or with me only, but this is the topic Ionic 2 beta9 - Toggle - ionChange