-
Notifications
You must be signed in to change notification settings - Fork 27.4k
ng-repeat='size in sizes' input ng-model='size[$index]' - duplicating values on .push() #1466
Comments
Hi! |
Try this http://jsfiddle.net/JPJd3/13/ ng-repeat needs to have stable model, in your case the model changes as the user types which confuses the ng-model. Once you create a stable model the issue goes away. Stable model means that the DOM is in sync with the object identities in the repeater. When you have '' and then you type 'b' as far as ng-repeat is concerned '' when away and 'b' was added, it can not deduce that really you are just changing the value. |
By the way, in your fiddle, you Actually any primitive will fail here: This is because, I guess, ng-model is receiving a |
Miško in your example, model binding breaks down if I use type url or type email for input. However it works with other types like search, text or tel. Is it supposed to be like this or it is a bug? Here is a fork with changed type http://jsfiddle.net/gleb_svechnikov/NQS7v/ |
@gleb-svechnikov invalid values have an undefined value, and the change listeners won't be called if the value changes from invalid -> invalid, because the value looks like it hasn't changed. This is still true in more recent versions of angular. |
shange |
I'm trying to bind to an array of arbitrary length, and add more values if certain constraints are met. In this fiddle, I want to add new inputs when all the other inputs have a value set.
http://jsfiddle.net/JPJd3/8/
As you can see after typing into the empty input, the value is replicated into the new input.
I've seen #905 and #1267, but I'm not sure if those apply here (the second one's fiddle is gone).
UPDATE: This works utilizing $timeout (original still seems like a bug):
http://jsfiddle.net/JPJd3/11/
The text was updated successfully, but these errors were encountered: