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.

Proposal : Use a custom compare function for objectEquality in $scope.$watch #10069

Description

@Toilal

It would be useful to be able to pass a function as the 3rd parameter objectEquality of $scope.$watch.

If a function is passed, is will be used instead of angular.equals to check for object equality.

var eq = function(newData, oldData) {
    ...
}

var cb = function() {
    ...
}

$scope.$watch('data',  cb, eq);

It could also provide better performance by implementing specific equality function for watched object.

My concrete use case : I have momentJS objects inside deep data to watch. But angular.equals doesn't work well with momentJS. For equality checking on momentJS object, moment#isSame must be used instead. Using this new functional parameter, i could delegate equality to lodash#isEqual which is able to customize object equality.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions