Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ion-toggle unnecessarily triggers change event when default value is true #6144

Closed
wli opened this issue Apr 12, 2016 · 8 comments
Closed

ion-toggle unnecessarily triggers change event when default value is true #6144

wli opened this issue Apr 12, 2016 · 8 comments
Assignees
Milestone

Comments

@wli
Copy link
Contributor

wli commented Apr 12, 2016

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:

  1. Create an ion-toggle with ngModel bound to a variable with a default value of true
  2. 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

@jgw96 jgw96 added the v2 label Apr 13, 2016
@danielcrk-cn
Copy link

I can confirm this.

@adamdbradley adamdbradley added this to the 2.0.0-beta.6 milestone Apr 14, 2016
@adamdbradley adamdbradley self-assigned this Apr 14, 2016
@cubicleWar
Copy link

It seems like this issue is back as of 2.0.0-beta.11

@jvelo
Copy link

jvelo commented Oct 8, 2016

I can reproduce on RC.0 as well

@asamuga
Copy link

asamuga commented Nov 14, 2016

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?

@ErvalhouS
Copy link

ErvalhouS commented Jan 29, 2017

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;
    }
 }

@mizdler
Copy link

mizdler commented Apr 9, 2017

The issue is still exists! I'm using ionic 2.4.8

@austinemayer
Copy link

I am now on Ionic 3.2.0 and this is still an issue. Has anyone been able to find fix for this?

@ionitron-bot
Copy link

ionitron-bot bot commented Sep 2, 2018

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.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Sep 2, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests