Which one handles exception automatically between $digest and $apply?

Answer Posted / swati maheshwari

$apply handle exceptions.
scope.$digest() will only fire watchers on current scope, scope.$apply will evaluate passed function and run $rootScope.$digest().

First one is faster, as needs to evaluate watchers for current scope, second one is slower (needs to evaluate watchers for$rootScope and all it's child scopes).

When error occurs in one of the watchers and you use scope.$digest, it's not handled via $exceptionHandler service, so you need to handle exception yourself. scope.$apply uses try catch block internally and passes all exceptions to $exceptionHandler.

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are static and public in angular?

450


What is decorator in angular?

390


What are the differences in ngmodules and javascript modules?

440


What are events in angularjs?

424


What are http interceptors?

394






What is @input and @output in angular 2?

430


Define services in angularjs.

408


What is angular 4? What’s new in angular 4?

422


Explain what is the difference between angularjs and backbone.js?

390


Explain the difference between angular.js and backbone.js?

437


What is angular framework?

429


Explain ng-model directive angularjs?

435


How to declare a component in angular 2?

439


Explain validations done in angularjs?

450


What is angular routing?

396