How to use a $watchGroup with object equality or deep-watch the properties in the group?

后端 未结 3 549
感动是毒
感动是毒 2020-12-15 07:14

I want a directive to re-render HTML whenever three scope variables have changed. The first two are just integers, the third is an array.

We have $watchGroup

3条回答
  •  天命终不由人
    2020-12-15 07:43

    I also had the same problem as yours.

    My solution to this deep watchgroup problem is:

    // Create new object to watch different types of objects
    var objectToBeWatch = {
        number1: number1, 
        number2: number2,
        myArray: myArray
    };
    
    $scope.$watch(
        function () {
            return objectToBeWatch;
    }, callback, true);
    

    I hope this helps!

提交回复
热议问题