Just modifying a previous answer...
Angular has a concept of ‘digest cycle’. You can consider it as a loop. In which Angular checks if there are any changes to all the variables watched by all the $scope
s (internally $watch()
and $apply()
functions are getting bonded with each variable defined under $scope
).
So if you have $scope.myVar
defined in your controller (that means this variable myVar
was marked for being watched) then you are explicitly telling Angular to monitor the changes on myVar
in each iteration of the loop. So when the value of myVar
changes, every time $watch()
notices and execute $apply()
to apply the changes in DOM.
This "Digest" is also called "dirty checking", because, in a way, it scans the scope for changes. As all watched variable are in a single loop (digest cycle), any value change of any variable forces to reassign values of other watched variables in DOM.
PROS: This is the way Angular achieves Two-way data binding.
CONS: If there are more watched variables in a single page (>2000–3000), you may see lag while page loading. (But I say if there are that many ‘watched variables’ in a single page, it is a bad page design :p).
There are other cons, as well as are workarounds also :D