简体   繁体   中英

Angular execute XHR request without triggering a digest

I have a scenario where I want to issue an XHR post to the server. I do not want to trigger a $rootScope.$digest() by doing so. I know I can manually create my own XMLHttpRequest to do this same thing, but I feel there should be a way to do this inside angularjs by default.

Anyone have any thoughts?

Check out $http:991 , the only way to get around it is turning on $rootScope.$$phase (a extremely fugly hack) , using an external library to accomplish it, or simply not caring about whether a request triggers a $digest cycle. The last one is what you should be gunning for.

Either use a external library , or get downright nasty .

$rootScope.$$phase = true;
$http.get('/foo').success(function () {
  $rootScope.$$phase = false;
});

Obviously not reccomended as lots of unexpected stuff might happen, so. Yeah, external library.

What you should really be doing is not considering getting around the whole point of Angular.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM