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

前端之家收集整理的这篇文章主要介绍了angularjs – Angular不立即发出$http请求前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个指令响应从输入元素触发的Blur事件,然后最终导致调用Angular $http服务以发出适当的HTTP请求. @H_404_7@

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

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

@H_404_7@角度v1.1.5

解决方法

原因 @H_404_7@

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

@H_404_7@

@H_404_7@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.

@H_404_7@一个办法

@H_404_7@正如帖子建议我触发$digest循环,这导致我的$http生成的请求立即被触发.

@H_404_7@

scope.$apply();

猜你在找的Angularjs相关文章