A use of the $ timeout and $ apply () that I do not know if it is correct in angularJs 1.xx

0

I have had an angularJs 1.xx development to review and I wanted to make sure that the usage I see is correct in many of the controllers of this construction:

 $timeout(function(){
     $rootScope.$apply();
 });

Especially within watcher functions

$scope.$watch(function() {}

What utility can it have. It should not even be enough:

$timeout(function(){

});

Can a doubt affect the performance of the angularJs development by injecting in many controllers the reference to $ rootScope if it is not used in it?

    
asked by Falinsito 29.10.2017 в 17:38
source

1 answer

0

@Falinsito you're not in the wrong way, the smart garbage collector of the browsers, even if you do not indicate that you should clean memory, as long as references do not seem to be used again.

This helps to correct many old errors caused by the issue of html generation associated with variables, especially in Jquery.

If this step technique is abused by reference especially of objects (in this case angularJs controllers) it will be very difficult for the garbage collector to work in optimal conditions.

If all this happens inside the ui-router of a large web application or with high requirements, it can be a way to reach the memoryLeak, cardiac arrest of the XD browser or yourself if you can not fix it while you they press for you to do it.

    
answered by 29.10.2017 в 18:05