0

I've read this Q/A about databinding and $apply -> $digest in AngularJS : How does data binding work in AngularJS?

While I understand the principle and the consequences, I'm still unsure about when AngulaJS is going to call $digest to do the dirty-checks. (And so, when should I consider to do something about the $watcher)

Every example I found was about using 'ng-click', 'ng-show', or 'ng-class'. But I'm pretty sure that it is also triggered by any change on variables of the scope ({{myData}}), and by many others directives (All of them maybe ?).

I would like to understand in which cases a $digest is called.

Can you give me any generic rule to knwo when it is called, or an exhaustive list of actions that will trigger a dirty-check ?

Community
  • 1
  • 1
Clément Malet
  • 5,062
  • 3
  • 29
  • 48

1 Answers1

2

Have a look at this:

angularjs docs, specifically at "Integration with the browser event loop" section.

Basically the way it works is that AngularJS binds event handlers to any element that interacts with angular (any element that has a directive attached to it) and every time that event fires, $apply is called which internally calls $digest which will trigger the reevaluation of all the $watches which will check for values changed, etc...

Wawy
  • 6,259
  • 2
  • 23
  • 23
  • I can't look at the docs at the moment, but I will give a look and accept your answer after that. But from what you said, basically **every** angularJS related action and change is going to call the $apply.$digest process. Did I got it right ? – Clément Malet Jun 27 '14 at 09:56