In AngularJS, there is the two-way data binding , which causes values to be immediately displayed in views even when this value is updated in controller .
In addition, there is also the $scope.$watch
function that knows exactly when a variable is changed and immediately calls an action when that happens.
My question is:
How does AngularJS do this?
I have this concern because in a system where I had to use several ng-repeat
followed by ng-models
, several watchers were generated and, with this, a great slowness in rendering the elements .
I know that in Vue a kind of observer is used in the property defined in the object. But I still can not figure out how this works in AngularJS.
-
Does Angular internally use some kind of loop ,
setInterval
, or something from JavaScript that allows you to watch change in variable values? I have this curiosity to understand how this can affect the performance and also to try to do something similar. -
If I use many watchers (which are generated by
ng-if
,ng-model
, and the like, plus the$scope.$watch
itself), can I damage the performance of my application? / p>