Digest cycle in angularjs

Digest cycle in angularjs is very same as any digestion process. As angularjs allows two way data binding, the change in model has to be applied to views or vice versa.

When an event is triggered which changes the model, angularjs initiates the digest cycle.

every time we bind data to view, an watcher is being initiated behind the scene to verify the changes which is similar to $watch. The digest cycle triggers the watchers which are continuously verifying the change in the model.

digest cycle runs maximum up to 10 times to compare the old value and the new value. It stops when they are same. Digest cycle starts at the $rootScope and propagates to each nested scope.

When you are using a JavaScript inbuilt function like setInterval instead of $interval to update the model then angularjs does not understand to trigger the digest cycle. That time we need to manually call the $scope.$apply() method to initiate the digest cycle.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s