Angular docs on scope state:
At the end of $apply, Angular performs a $digest cycle on the root scope, which then propagates throughout all child scopes. During the $digest cycle, all $watched expressions or functions are checked for model mutation and if a mutation is detected, the $watch listener is called.
I wonder why does every $apply call a $digest on root scope? Wouldn't it be sometimes possible to detect which scope was modified and call $digest only on that scope and it's descendants.
For example take that controller and a view:
angular.module("aModule")
.controller("aController", function($scope) {
$scope.increase = function() {
$scope.aValue += 1;
};
});
<div ng-controller="aController">
<button ng-click="increase()">Increase</button>
</div>
Would clicking the button really run $digest loop on the root scope? Why not run it only on aController scope and it's descendants?
$rootScope.aValue += 1? What if it modified the state of an object that is referenced by the root scope, or any other scope? - JB Nizet