Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to disable triggering of $digest on every $http.get?

Background

angular's $http service is triggering a $digest on every get (if no $digest is already running):

if (!$rootScope.$$phase) $rootScope.$apply();  

Ia addition to fetching objects from our API, our app has many directives with templateUrl - which are fetched by angular using $http. This causes hundreds of $digest loops on cold start.

Commenting out the above line, reduces the number of $digest loops to about 3, and the app runs MUCH faster, with no bindings broken (at least due to $http not triggering a $digest).

Question

Is there a way to disable $http triggering the $digest?

like image 475
seldary Avatar asked Aug 28 '14 12:08

seldary


1 Answers

use $httpProvider.useApplyAsync(true); on app config. then the templates directive loaded within 10ms will face the same digest. this will reduce the digest cycle call. see here

like image 101
Fisherman Avatar answered Sep 19 '22 07:09

Fisherman