Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Model and view gets out of sync with checkboxes #686

Closed
hekke opened this issue Dec 7, 2011 · 4 comments
Closed

Model and view gets out of sync with checkboxes #686

hekke opened this issue Dec 7, 2011 · 4 comments

Comments

@hekke
Copy link

hekke commented Dec 7, 2011

http://jsfiddle.net/hekke/mmH63/2/

Try clicking the first checkbox - it marks both the first and second as checked, but the model is ok.

Tested in Chrome 15 and Firefox 8

Edit: updated the fiddle with loop over a different array. Then it works??

@mhevery
Copy link
Contributor

mhevery commented Dec 14, 2011

here is a working version: http://jsfiddle.net/mmH63/4/

In a strange way this is kind of makes sense, but it is not what you want.
The issue is that the ng:repeat keeps the elements in sync with the order
of elements in the array, but there is no way to tell the difference
between the first and second true element, since they are both associated
with three different input elements. So when you change first false into
true, it is not clear for ng:repeat which input element it should remove
and replace with new instance of the true input.

Not exactly sure how to fix that.

2011/12/7 Henrik Jørgensen <
reply@reply.github.com

http://jsfiddle.net/hekke/mmH63/1/

Try clicking the first checkbox - it marks both the first and second as
checked, but the model is ok.

Testet in Chrome 15 and Firefox 8


Reply to this email directly or view it on GitHub:
#686

@hekke
Copy link
Author

hekke commented Dec 14, 2011

But the thing is - it worked in the 0.10.2 release:

http://jsfiddle.net/hekke/mmH63/6/

In 0.10.3+ there's only a problem when looping over the same array as I'm indexing into. It's easy to work araound, but what scares me is what else is lurking behind this odd behavior. For an updated 0.10.3+ example, see:

http://jsfiddle.net/hekke/mmH63/2/

@mhevery
Copy link
Contributor

mhevery commented Dec 14, 2011

it worked because 0.10.3 did not have stable repeaters and so it was not effected by this issue. Stable repeaters is a feature which keeps the array you are iterating over and the elements in sync, which means that adding an object in the middle of the array will cause a new element to be added to DOM at the same position. But if you have an array such as [true, true], and you change it to [true, false] it is not clear what just happened and how should the DOM behave.

@hekke
Copy link
Author

hekke commented Dec 14, 2011

That makes sense. I'm content with that explanation.

@hekke hekke closed this as completed Dec 14, 2011
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

2 participants