加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular不立即发出$http请求

发布时间:2020-12-17 18:02:10 所属栏目:安全 来源:网络整理
导读:我有一个指令响应从输入元素触发的Blur事件,然后最终导致调用Angular $http服务以发出适当的HTTP请求. 正确调用$http服务并生成预期的承诺,但实际的HTTP请求不会立即生成.它仅在进行其他类型的DOM交互后才会触发. 为什么不立即提出请求?我怎么能强迫他们马
我有一个指令响应从输入元素触发的Blur事件,然后最终导致调用Angular $http服务以发出适当的HTTP请求.

正确调用$http服务并生成预期的承诺,但实际的HTTP请求不会立即生成.它仅在进行其他类型的DOM交互后才会触发.

为什么不立即提出请求?我怎么能强迫他们马上制作呢?

角度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();

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读