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

Improve support for collections in ngModelController #7203

Closed

Description

@groner

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.

Activity

  1. groner commented on Apr 22, 2014

    @groner
    ContributorAuthor

    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.

  2. added this to the milestone on Jul 1, 2014
  3. Narretz commented on Sep 9, 2014

    @Narretz
    Contributor

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

  4. Narretz commented on Dec 10, 2014

    @Narretz
    Contributor

    Let's track this here: #5449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions