December 2014
Intermediate to advanced
346 pages
6h 14m
English
You might find that multiple model components need to be tied to the same $watch type callback. As of the 1.3 release, AngularJS provides the $watchGroup method that accepts a collection of watch targets in which all the watch targets need to bind to the same callback.
The change event callback parameters can be an ordered array of the current values, followed by an ordered array of the previous values. This is shown here:
(app.js) angular.module('myApp',[]) .controller('Ctrl', function($scope, $log) { $scope.ping = 'pong'; $scope.ding = { dong: 'ditch' }; // watch ping and the ding.dong property by reference $scope.$watchGroup(['ping', 'ding.dong'], function(newVals, oldVals, scope) { // callback ...Read now
Unlock full access