December 2014
Intermediate to advanced
272 pages
8h 17m
English
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';});
Read now
Unlock full access