angularjs - Angular 没有立即发出 $http 请求

标签 angularjs

我有一个指令对从输入元素触发的 Blur 事件使用react,然后最终导致调用 Angular $http 服务以发出适当的 HTTP 请求。

$http 服务被正确调用并生成预期的 promise ,但是实际的 HTTP 请求不会立即发出。只有在进行其他类型的 DOM 交互后才会触发。

为什么不立即提出请求?我怎样才能强制它们立即制作?

Angular v1.1.5

最佳答案

原因

我最终在 GitHub ( https://github.com/angular/angular.js/issues/2442 ) 上的问题中找到了答案:

v1.1.4... changed the way $http worked so that it was scheduled on nextTick instead of firing immediately. This means that if your $http is scheduled from something that doesn't cause a $digest to fire then your request won't be sent. You can verify that this is the behavior you're seeing by clicking on the page a few times (anywhere) and you should see your request go out.



一个办法

正如帖子所建议的那样,我触发了一个 $digest 循环,这导致我的 $http 生成的请求立即被触发。
scope.$apply();

关于angularjs - Angular 没有立即发出 $http 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17039998/

相关文章:

javascript - Angularjs $scope、数据绑定(bind)和变量更改。

regex - Angular 输入限制指令 - 否定正则表达式

javascript - 将 angularjs 与静态 jsonp 一起使用只能使用一次

javascript - 从外部指令访问表单验证

javascript - 使用 jsdom 更改 HTML 标签

angularjs - 独立管理独立AngularJS指令之间的通信

angularjs - 将 ng-include 与模板缓存一起使用

javascript - 更改图像的特定区域并在该区域填充颜色

javascript - AngularJS 中的通用 getterSetter

angularjs - 如何使用 ng-transclude 扩展 md-autocomplete? [在模板中非法使用 ngTransclude 指令!]