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

Checkbox Infinite Loop #812

Closed
renevall opened this issue Jul 5, 2016 · 8 comments
Closed

Checkbox Infinite Loop #812

renevall opened this issue Jul 5, 2016 · 8 comments
Assignees
Labels
P2 The issue is important to a large percentage of users, with a workaround
Milestone

Comments

@renevall
Copy link

renevall commented Jul 5, 2016

Bug, feature request, or proposal:

Bug

What is the expected behavior?

Setting

<li *ngFor="let item of data">
    <md-checkbox [checked]="item.checked" (change)="item.checked=!item.checked"> 
    {{item.name}}
    </md-checkbox>

Should change the source value and update data once on click/change

What is the current behavior?

The checkbox goes on an infinite switching loop

What are the steps to reproduce?

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

Simpler version:

https://plnkr.co/edit/OhqPeWHnjfvkxyNObETc?p=preview

Providing a Plunker (or similar) is the best way to get the team to see your issue.
Plunker template: http://plnkr.co/edit/o077B6uEiiIgkC0S06dd

@mmrath
Copy link

mmrath commented Jul 5, 2016

I think this is related to #575

I believe there is WIP to make md-check-box behave like native checkbox and fire onchange only if the control is in focus. That probably should resolve this

@renevall
Copy link
Author

renevall commented Jul 5, 2016

@mmrath I guess they are related at some level. But I checked your plnkr and I didn't see the infinite loop.

The on change on focus will be welcome, since in theory will allow me to keep two controls binded to one data source. As of right now, since both react on change, they just keep calling each others change. Or so it seems.

@renevall
Copy link
Author

renevall commented Jul 5, 2016

#582

@jelbourn
Copy link
Member

jelbourn commented Jul 6, 2016

@ReneVallecillo What version of angular material were you using?

@renevall
Copy link
Author

renevall commented Jul 6, 2016

@jelbourn The infinite loop shows on the plunker, which is using the suggested template. On my repo, I'm using version alpha6 but something different but related may be happening.

What is happening in my repo is, since I have two components bound to a single data source, the change is triggering in both components and that seems to trigger @ #575 as:

  1. Checkbox component 1 is checked, change event is triggered
  2. Data source is updated
  3. Checkbox component 2 is checked, but change event is also triggered
  4. ???
  5. Endless Loop.

Or so it seems. This should be fixed with #791. But in my repo what it shows is angular/angular#6005 (comment)

I think this prevents the endless loop to show on my repo.

But I don't understand why it happens here:

https://plnkr.co/edit/OhqPeWHnjfvkxyNObETc?p=preview

It is a really basic code.

TLDR, I'm on alpha 6, but while replicating my code on plunker, the endless loop happens.

@jelbourn
Copy link
Member

I think this will be fixed by #820.

@jelbourn jelbourn added has pr P2 The issue is important to a large percentage of users, with a workaround labels Jul 14, 2016
@jelbourn jelbourn added this to the alpha.7 milestone Jul 14, 2016
@devversion
Copy link
Member

devversion commented Jul 15, 2016

@jelbourn Just confirmed with #820, and it seems to fix that issue.

It's just important (again) to make the adjustments with the emitted MdSlideToggleChange class.

<md-checkbox ... (change)="item.checked = $event.checked">

@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
P2 The issue is important to a large percentage of users, with a workaround
Projects
None yet
Development

No branches or pull requests

4 participants