Watch multiple $scope attributes

Starting from AngularJS 1.3 there’s a new method called $watchGroup for observing a set of expressions.

$scope.foo = 'foo';
$scope.bar="bar";

$scope.$watchGroup(['foo', 'bar'], function(newValues, oldValues, scope) {
  // newValues array contains the current values of the watch expressions
  // with the indexes matching those of the watchExpression array
  // i.e.
  // newValues[0] -> $scope.foo 
  // and 
  // newValues[1] -> $scope.bar 
});

Leave a Comment