简体   繁体   English

角执行XHR请求而不触发摘要

[英]Angular execute XHR request without triggering a digest

I have a scenario where I want to issue an XHR post to the server. 我有一种情况,我想向服务器发出XHR帖子。 I do not want to trigger a $rootScope.$digest() by doing so. 我不想这样做触发$ rootScope。$ digest()。 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. 我知道我可以手动创建自己的XMLHttpRequest来执行相同的操作,但是默认情况下,我觉得应该在angularjs中执行此操作。

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. 看看$ http:991 ,解决它的唯一方法是打开$rootScope.$$phase (一个非常丑陋的hack) ,使用一个外部库来完成它,或者根本不关心请求是否触发了$digest周期。 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 您真正应该做的是不考虑解决Angular.js的全部问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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