ion-toggle unnecessarily triggers `change` event when default value is true
Short description of the problem:
ion-toggle unnecessarily triggers change event when the default value is true
What behavior are you expecting?
The change event should not fire until the user presses the toggle
Steps to reproduce:
- Create an ion-toggle with ngModel bound to a variable with a default value of true
- Observe change event firing without any user input
toggle: boolean = true;
<ion-toggle [(ngModel)]="toggle"
(change)="onUpdateToggle($event)"></ion-toggle>
Other information: (e.g. stacktraces, related issues, suggestions how to fix, stackoverflow links, forum links, etc)
This only fires when the default value is true.
Which Ionic Version? 1.x or 2.x 2.0.0-beta.4
Plunker that shows an example of your issue
http://plnkr.co/edit/f2NSVLP1DETbkyFmpSN8?p=preview
Run ionic info from terminal/cmd prompt: (paste output below)
Cordova CLI: 6.0.0
Ionic Framework Version: 2.0.0-beta.4
Ionic CLI Version: 2.0.0-beta.24
Ionic App Lib Version: 2.0.0-beta.14
OS: Distributor ID: Ubuntu Description: Ubuntu 15.10
Node Version: v5.8.0
I can confirm this.
It seems like this issue is back as of 2.0.0-beta.11
I can reproduce on RC.0 as well
Any update on this? In my case ion-toggle, ionChange runs on initial ngFor if value is set to true. I dont want that. Has anyone found a solution?
Well, my fix is set the change function to fire only if I set a boolean value to true, while setting it to false on the event itself and the component constructor. Then, put one tap event function to set it to true, magic 💃, but not ideal.
export class MyComponent {
constructor() {
this.enableCallback = false;
}
functionCalledOnChange() {
if (this.enableCallback) {
//Your logic *here*
this.enableCallback = false;
}
}
functionCalledOnTap() {
this.enableCallback = true;
}
}
The issue is still exists! I'm using ionic 2.4.8
I am now on Ionic 3.2.0 and this is still an issue. Has anyone been able to find fix for this?
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out.