AngularJS $watch vs $watchCollection: which is better for performance?

$watch() will be triggered by: $scope.myArray = []; $scope.myArray = null; $scope.myArray = someOtherArray; $watchCollection() will be triggered by everything above AND: $scope.myArray.push({}); // add element $scope.myArray.splice(0, 1); // remove element $scope.myArray[0] = {}; // assign index to different value $watch(…, true) will be triggered by EVERYTHING above AND: $scope.myArray[0].someProperty = “someValue”; JUST ONE MORE … Read more

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 … Read more