Process all of the watchers
of the current scope and its children.
Because a watcher
's listener can change the model, the
$digest()
keeps calling the watchers
until no more listeners are
firing. This means that it is possible to get into an infinite loop. This function will throw
'Maximum iteration limit exceeded.'
if the number of iterations exceeds 100.
Usually you don't call $digest()
directly in
controllers
or in directives
.
Instead a call to $apply()
(typically from within a
directive
) will force a $digest()
.
If you want to be notified whenever $digest()
is called,
you can register a watchExpression
function with $watch()
with no listener
.
You may have a need to call $digest()
from within unit-tests, to simulate the scope
life-cycle.
var scope = angular.scope(); scope.name = 'misko'; scope.counter = 0; expect(scope.counter).toEqual(0); scope.$digest('name', function(scope, newValue, oldValue) { counter = counter + 1; }); expect(scope.counter).toEqual(0); scope.$digest(); // no variable change expect(scope.counter).toEqual(0); scope.name = 'adam'; scope.$digest(); expect(scope.counter).toEqual(1);
angular.scope.$digest();