Skahrz Skahrz - 1 year ago 115
Javascript Question

Dirty checking on angular

I was reading some article to understand a little bit more how angular.js works.

One of the terms that I didn't understand is "dirty checking".

What is it exactly? It seems like an observer pattern but apparently it's better.

Can you help me understand this please?

Thanks in advance.

Answer Source

From this link:

Angular defines a concept of a so called digest cycle. This cycle can be considered as a loop, during which Angular checks if there are any changes to all the variables watched by all the $scopes. So if you have $scope.myVar defined in your controller and this variable was marked for being watched, then you are explicitly telling Angular to monitor the changes on myVar in each iteration of the loop.

This "digest" is also called "dirty checking", because, in a way, it scans the scope for changes. I cannot say if it's for better or for worse than observable pattern. It depends on your needs.

Some links: