Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • AngularJS $digest

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 429
    Comment on it

    Since AngularJS has a popular concept of two way data binding. But how does it comes to know that a value has changed? Here comes the role of $digest

     

    AngularJS executes in cycles which is called as $digest cycle. Suppose we change a scope model by calling any function on ng-click directive. As soon as the the click event is fired, Angular triggers the digest cycle by calling $digest(). Now, when this digest cycle executes, it fires each of the watchers. These watchers then checks if the value of any scope model has changed,i.e. if the new value is different from the last value. If it encounters any change, then it triggers the corresponding listener function and as result the view gets updated with the new value.

    If there is no change, it keeps calling the watchers until no listeners are firing. So it may cause an infinite loop. For this case an exception is thrown- 'Maximum iteration limit exceeded.'  if the number of iterations exceeds 10.

     

    $digest doesn’t executes by itself. Instead Angular calls $scope.$apply which then invokes $digest. This means that the digest cycle starts at $rootscope and subsequently visits all the child scopes.

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: