Hi there,
I believe ion-toggle’s ionChange is triggered on page load on ionic 5, if the page is opened on a second time. I saw another bug report on ionic 3 which occurred while the form was populated. Likely it’s related.
Steps to reproduce:
- Open the page
- Click back
- Open the page again (bug occurs here).
The code
<ion-list *ngIf="settingsData">
<ion-item *ngFor="let s of settingsData.getKeys()" detail="false">
<ion-label>{{s}}</ion-label>
<ion-toggle [(ngModel)]="settingsData[s]" (ionChange)="settingChanged(s)"></ion-toggle>
</ion-item>
</ion-list>
public async ngOnInit(){
this.settingsData = await timer(100).toPromise().then( () => ({
label_1: true,
label_2: true,
label_3: true
}) );
}
public settingChanged(settingKey: string) {
console.log("changed: "+settingKey);
}
The environment
$ ionic info
Ionic:
Ionic CLI : 6.11.0 (/home/vagrant/.config/yarn/global/node_modules/@ionic/cli)
Ionic Framework : @ionic/angular 5.3.1
@angular-devkit/build-angular : 0.1000.6
@angular-devkit/schematics : 10.0.6
@angular/cli : 10.0.6
@ionic/angular-toolkit : 2.3.0
Capacitor:
Capacitor CLI : 2.4.0
@capacitor/core : 2.4.0
Utility:
cordova-res : not installed
native-run (update available: 1.1.0) : 1.0.0
System:
NodeJS : v12.18.3 (/home/vagrant/.nvm/versions/node/v12.18.3/bin/node)
npm : 6.14.6
OS : Linux 4.9