-
Notifications
You must be signed in to change notification settings - Fork 27.4k
fix(input): detect changes in array when its values are changed #2553
Conversation
When model value is an array, its values must be stored in a new array to allow a comparison between old and new values when checking if a value is out of sync with the model. Closes angular#1751
Do you have a use case outside of ngList? If not then perhaps we should look at a more focussed fix on the ngList directive? Perhaps ngModelController should provide an option to watch the model "deeply", i.e. if this flag is set then compare the model values with angular.equal rather than ===. Then the ng-list directive could set this flag. Moreover other custom directives could use this too. |
I think that should be the way to go. I can imagine a directive that can map an input value to an object as ngList does to an array. In this case, it won't work again. I'll look at the flag option and I'll make a proposal on this. |
There are two ways how to watch an expression - shallow and deep (check out http://docs.angularjs.org/api/ng.$rootScope.Scope#$watch third argument). I think proper fix is to allow configuration for ng-model to specify deep watching. For inputs, it might be fine to do deep watching by default (as most of the time, the watched value is a primitive type), the problem is selects, where you typically watch objects and you wanna compare them by reference. I'm closing this, as this solution is not what we want. |
Sorry @petebacondarwin I missed your comment, just read it. Yep, I like your suggestion - that's the right fix. |
Following some of your suggestions, I made it configurable whether to compare by equality or by reference. When using comparison by equality, the value is copied to You can see the changes in this commit: @vojtajina About using the |
We also have the new scope.$watchCollection |
@gonzaloruizdevilla - perhaps something like:
or more flexible but less well defined
or more flexible still but potentially tricky
|
Is there an open issue tracking support for collections with ng-model? |
Hmmm... I'm just thinking that we could add a new option into |
I'm not sure this needs to be exposed to markup. Binding an ng-model as a On Mon, Apr 21, 2014 at 5:04 PM, Luis Ramón López
|
When model value is an array, its values must be stored in a new array
to allow a comparison between old and new values when checking
if a value is out of sync with the model.
Closes #1751