Ion-toggle (ionChange)

I have a problem with ion-toggle (ionChange)

Browser stops when i try to navigate to the page where it contains <ion-toggle> with (ionChange)

If i remove (ionChange), the app works find, but with (ionChange) doesn’t work.

here is the code

<ion-toggle color="primary" [(ngModel)]="alertEvent" (ionChange)="alertEventChange()"></ion-toggle>

alertEventChange() {
(this.alertEvent)? this.alertEvent=false: this.alertEvent=true;
this.userData.changeEventAlertStatus();
}

this code works find if (ionChange) is removed.

How can I use ionChange???
Thank you

this is my ionic info

Cordova CLI: 6.2.0
Ionic CLI Version: 2.1.0
Ionic App Lib Version: 2.0.0-beta.20
ios-deploy version: 1.8.6
ios-sim version: Not installed
OS: Mac OS X El Capitan
Node Version: v5.0.0
Xcode version: Xcode 7.3.1 Build version 7D1014

(ionChange) seems to be fine, I hope you have problem with some other part of code.

<ion-toggle color="primary" [(ngModel)]="alertEvent" (ionChange)="alertEventChange()"></ion-toggle>

alertEventChange() { this.alertEvent = this.alertEvent ? false : true; console.log(this.alertEvent); }

above code for simple toggle is working fine.

1 Like

@dpark1985 Use [ng-model] instead of [(ng-model)] here.