Why does $ digest start all watches that have been registered in the area?

I was wondering why $ digest starts all the watches that have been registered in the scope, if you have several inputs with data coming from the scope, then why AngularJS has to dirty check all the hours of the scope when, for example, only one input field is bound to the label?

+4
source share
1 answer

Angular is not clairvoyant; he does not know what your observers are doing, except by checking their value. If something can change, which could potentially mean that the displayed data needs to be updated, Angular will check all of your observers. If something never needs to be checked, it should not have an observer.

Of course, it is possible that you have something that you only need to bind once and will not change after that, which means that it does not need to be constantly checked. I'm not sure if there is a standard solution for this, but here is a Github project that provides a one-time binding for Angular .

0
source

Source: https://habr.com/ru/post/1537960/


All Articles