$scope.$evalAsync() vs. $timeout() In AngularJS
$scope.$evalAsync() vs. $timeout() In AngularJS
Sometimes, in an AngularJS application, you have to explicitly tell AngularJS when to initiate it's $digest() lifecycle (for dirty-data checking). This requirement is typically contained within a Directive; but, it may also be in an asynchronous Service. Most of the time, this can be easily accomplished with the $scope.$apply() method. However, some of the time, you have to defer the $apply() invocation because it may or may not conflict with an already-running $digest phase. In those cases, you can use the $timeout() service; but, I'm starting to think that the $scope.$evalAsync() method is a better option...
Written by Rick Huizinga
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Angular
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#