$watch not being triggered on array change

后端 未结 4 1798
北荒
北荒 2020-12-08 00:29

I\'m trying to figure out why my $watch isn\'t being triggered. This is a snippet from the relevant controller:

$scope.$watch(\'tasks\', functi         


        
4条回答
  •  没有蜡笔的小新
    2020-12-08 01:09

    For one dimensional arrays you may use $watchCollection

    $scope.names = ['igor', 'matias', 'misko', 'james'];
    $scope.dataCount = 4;
    
    $scope.$watchCollection('names', function(newNames, oldNames) {
      $scope.dataCount = newNames.length;
    });
    

提交回复
热议问题