jbutko
1/22/2015 - 11:39 AM

#AngularJS, #JS: Watch multiple $scope attributes #JavaScript

#AngularJS, #JS: Watch multiple $scope attributes #JavaScript

$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 
});

// via From http://stackoverflow.com/questions/11952579/watch-multiple-scope-attributes