Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$scope.$evalAsync vs $scope.$applyAsync

Tags:

dom

angularjs

What is the difference between $evalAsync and $applyAsync? My understanding is that when I use $evalAsync from a directive, the expression will evaluate before the browser renders.

So as an example, if I wanted to scroll to a particular position on a page but not show the jump to that spot, I could use this to scroll to the position and since it fires before the browser has rendered, this visual bug would be gone.

However, what is the purpose of applyAsync? When is it a good idea to use one over the other?

like image 772
puopg Avatar asked Jun 11 '15 18:06

puopg


People also ask

What is the use of $rootScope?

Root Scope All applications have a $rootScope which is the scope created on the HTML element that contains the ng-app directive. The rootScope is available in the entire application. If a variable has the same name in both the current scope and in the rootScope, the application uses the one in the current scope.

How many $rootScope an AngularJS application can have?

All the $scopes of an AngularJS application are children of the $rootscope. An app can have only one $rootScope.

What is scope digest?

Generally in angularjs whenever we create variables along with $scope object those variables will be added to the watch list. In angularjs $digest() function is a central function of $scope object and it is used to iterate through the watch list items and check if any variable value has been modified or not.

What is scope in AngularJS?

The Scope in AngularJS is the binding part between HTML (view) and JavaScript (controller) and it is a built-in object. It contains application data and objects. It is available for both the view and the controller. It is an object with available properties and methods. There are two types of scopes in Angular JS.


1 Answers

The

$evalAsync()

will execute in the current digest

$applyAsync()

in a scheduled one.

If you need details: Ben Nadel or stack here

like image 54
Luckylooke Avatar answered Sep 19 '22 21:09

Luckylooke