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

slide-toggle fires undesired event when setting a default value #4124

Closed
fernandobandeira opened this issue Apr 17, 2017 · 2 comments · Fixed by #4140 or #4220
Closed

slide-toggle fires undesired event when setting a default value #4124

fernandobandeira opened this issue Apr 17, 2017 · 2 comments · Fixed by #4140 or #4220
Assignees
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent

Comments

@fernandobandeira
Copy link

Bug

Currently if you set a default value for a slide-toggle it'll emit a ngModelChange event when the view inits, IMO the correct behavior would be to not emit this event since there was no change at all.

What are the steps to reproduce?

http://plnkr.co/edit/imQpobzGdi3Xl6IbXYo7?p=preview

Or use the component below:

import { Component } from '@angular/core';

@Component({
  selector: 'demo-app',
  template: `
    <md-slide-toggle [(ngModel)]="test" (ngModelChange)="change()"></md-slide-toggle>
    <hr>
    <div [hidden] = "hide_msg">
        Change event was received:
    </div>
  `
})
export class AppComponent {
  hide_msg: boolean = true;
  test = true;
  
  change() {
    this.hide_msg = false;
  }
}

Which versions of Angular, Material, OS, browsers are affected?

All browsers and Angular versions...

Even changing test to 1 the event will also be fired...

@devversion devversion self-assigned this Apr 17, 2017
@devversion
Copy link
Member

Thanks for the issue. I will look into it tomorrow.

devversion added a commit to devversion/material2 that referenced this issue Apr 18, 2017
While initially looking into angular#4124, there were a few more issues inside
of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Apr 18, 2017
While initially looking into angular#4124, there were a few more issues inside
of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Apr 18, 2017
While initially looking into angular#4124, there were a few more issues inside
of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
@kara kara added the P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent label Apr 18, 2017
devversion added a commit to devversion/material2 that referenced this issue Apr 21, 2017
While initially looking into angular#4124, there were a few more issues inside
of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Apr 22, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Apr 30, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Jun 12, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Jun 14, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Jun 14, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Jun 22, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
mmalerba pushed a commit that referenced this issue Jul 6, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
mmalerba pushed a commit that referenced this issue Jul 6, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
mmalerba pushed a commit that referenced this issue Jul 6, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
mmalerba pushed a commit that referenced this issue Jul 6, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
devversion added a commit to devversion/material2 that referenced this issue Jul 16, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
devversion added a commit to devversion/material2 that referenced this issue Jul 23, 2017
…r#4218)

While initially looking into angular#4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes angular#4124.
andrewseguin pushed a commit that referenced this issue Jul 27, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
andrewseguin pushed a commit that referenced this issue Jul 27, 2017
While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.
andrewseguin pushed a commit that referenced this issue Jul 28, 2017
* fix(slide-toggle): invalid model change event (#4140)" (#4218)

While initially looking into #4124, there were a few more issues inside of the slide-toggle.

* ngModelChange event is dispatched at initialization.

* Checked state isn't synchronized when state changes through drag. New state after dragging got overwritten by click event on label.

* Removes unnecessary logic inside of `change` listener. Change event doesn't fire if underlying checkbox is disabled.

Fixes #4124.

* Cast NgModel value to a boolean

* Properly mark component for check
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
P3 An issue that is relevant to core functions, but does not impede progress. Important, but not urgent
Projects
None yet
3 participants