-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Closed
Labels
P2The issue is important to a large percentage of users, with a workaroundThe issue is important to a large percentage of users, with a workaround
Milestone
Description
Note: for support questions, please use one of these channels:
https://github.com/angular/material2/blob/master/CONTRIBUTING.md#question.
This repository's issues are reserved for feature requests and bug reports.
- Do you want to request a feature or report a bug?
Report a bug - What is the current behavior?
When the underlying data represented by an md-checkbox changes, Angular complains that the 'checked' attribute of the checkbox has changed after it was checked - If the current behavior is a bug,
please provide steps to reproduce and if possible a minimal demo of the problem
via https://plnkr.co or similar.
I can't find a good base plunkr to work off - Create a Plunker template using angular2-material #309
if you have:
<md-checkbox [(ngModel)]="selected">
And, in the component:
setInterval(() => {this.selected = !this.selected}, 1000)
Angular will throw an error.
- What is the expected behavior?
The checkbox should update without an error - What is the motivation / use case for changing the behavior?
So that md-checkboxes stay in sync with their underlying data - Which version of Angular and Material, and which browser and OS does this issue affect?
Did this work in previous versions of Angular / Material?
Please also test with the latest stable and snapshot versions.
Tested on 2.0.0.alpha-2 in Chrome - Other information
(e.g. detailed explanation, stacktraces, related issues, suggestions how to fix)
I spent some time on this with the original sketch angular-material checkboxes, and I don't think it's possible to have internal state that is updated by writeValue in a ControlValueAccessor, as writeValue is called when changes are propagated to the view. I worked around it by only using the DOM (specifically the aria-checked attribute) to store the checkbox state, and getting rid of the checked variable. This is closer to what the ControlValueAccessor for standard inputs does, and fixes the issue.
omerfarukyilmaz and rushi216
Metadata
Metadata
Assignees
Labels
P2The issue is important to a large percentage of users, with a workaroundThe issue is important to a large percentage of users, with a workaround