$ watchCollection () with nested arrays

I have a nested form array:

$scope.itinerary = 
    [
        [
          {name:'x'},
          {name:'y'},
          {name:'z'}
        ],
        [
          {name:'a'},
          {name:'b'},
          {name:'c'}
        ]
    ]

And I do $ watchCollection using the following:

$scope.$watchCollection(function () {
            return $scope.itinerary;
        }, 
        function () {
            console.log("Changed")
        }
);

But it console.log()is executed only if one of the auxiliary arrays is deleted or a new array is added. If I move an element from one array to another, nothing will happen. (for example, when I move {name:'a'}from one array to another, nothing happens). How to set the clock to a nested array?

+4
source share
2 answers

$watch() " ". "" , AngularJS . , $digest AngularJS , ( ). ; .

$scope.$watch('itinerary',function (newVal,oldVal) {
          console.log(newVal)      

 },true);
+8

, $watchCollection, $watch , true.

, , , .

angular.eaquals , angular.copy.

https://docs.angularjs.org/api/ng/type/ $rootScope.Scope # $watch

+1

All Articles