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

Improve support for collections in ngModelController #7203

Closed
groner opened this issue Apr 22, 2014 · 3 comments
Closed

Improve support for collections in ngModelController #7203

groner opened this issue Apr 22, 2014 · 3 comments

Comments

@groner
Copy link
Contributor

groner commented Apr 22, 2014

Writing directives to handle input of collections (lists or objects) is currently not very well supported because ngModelController uses identity tests to determine if the model or view value changes.

Adding a collection watch mode to ngModelController would allow for more robust input directives such as checkbox lists to work without having to do things like creating new lists on every update or monkey patching the ngModelController instance.

This issue has come up a few times, but the only place I could find it yesterday was in #2553, which is closed.

@groner
Copy link
Contributor Author

groner commented Apr 22, 2014

I'm considering writing a patch for this, but I'd like some input on the API.

Possibilities I've considered and rejected are:

  • model.$watcher = function() { ... }, doesn't address the comparisons that happen outside of the watcher function.
  • model.$isEqual = function(curr, prev) { ... } requires copying lists and objects for later comparison, we may as well just use scope.$watchCollection().
  • model.$collectionMode = true is pretty simple and it could be observed inside ngModelWatch() and $setViewValue(), but I think we want scope.$watchCollection().

So I think the API that would work is model.$collectionMode(true).

This still feels a bit funny to me because the watch has already started by the time we're calling it so the $collectionMode function has to undo the initial watch and start a collection watch. Maybe moving the watch to the linking function and adjusting priority could work around this? I guess I could try it and see what breaks.

@Narretz Narretz added this to the Backlog milestone Jul 1, 2014
@btford btford removed the gh: issue label Aug 20, 2014
@Narretz
Copy link
Contributor

Narretz commented Sep 9, 2014

In #5449 @petebacondarwin suggested to use the modelEquality parameter for $watch.

@Narretz
Copy link
Contributor

Narretz commented Dec 10, 2014

Let's track this here: #5449

@Narretz Narretz closed this as completed Dec 10, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants