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.

select multi: $render is called twice when $viewValue reference changes #11329

Closed
@tomyam1

Description

@tomyam1

In the select directive there is a deep watch that calls $render if $viewValue deep-changes. This happens either if it changes inside or if it's reference changed.

It should only call $render in the first cases.

If the reference of $viewValue changes than this call is redundant because the shallow watch in ngModel will call $render.

I suggest something like:

    var lastView, lastViewRef = NaN;
    scope.$watch(fucntion() {
      if (lastViewRef === ngModelCtrl.$viewValue and !equals(lastView, ngModelCtrl.$viewValue)) {
        lastView = shallowCopy(modelCtrl.$viewValue);
        modelCtrl.$render();
      }
      lastViewRef = ngModelCtrl.$viewValue;
    })

Edit: Here is a plunker that show the issue
http://plnkr.co/edit/dWpTKH?p=preview

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions