Using $watchGroup to Track Multiple Scope Variables

AngularJS also provides the capability to watch an array of expressions using the $watchGroup method. The $watchGroup method works the same as $watch except that the first parameter is an array of expressions to watch. The listener will be passed an array with the new and old values for the watched variables. For example, if you wanted to watch the variables score and time, you would use this:

$scope.score = 0;
$scope.time = 0;
$scope.$watchGroup(['score', 'time'], function(newValues, oldValues) {
  if(newValues[0] > 10){
    $scope.status = 'win';
  } else if (newValues[1] > 5{
    $scope.status = 'times up';
});

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset