角赚不到$ HTTP请求立即 [英] Angular not making $http requests immediately

查看:75
本文介绍了角赚不到$ HTTP请求立即的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有反应,从输入元素发射了一枚模糊事件的指令,然后最终导致对角$ HTTP服务的调用进行适当的HTTP请求。​​

I have a directive that reacts to an Blur event fired from an input element, and then ultimately results in a call to the Angular $http service to make an appropriate HTTP request.

在$ HTTP服务被调用正确并产生预期的承诺,但是实际的HTTP请求没有得到立即作出。后来制作DOM交互等各类后才能触发。

The $http service is being called correctly and generating the expected promise, however the actual HTTP request does not get made immediately. It is only triggered later after making other kinds of DOM interactions.

为什么请求没有立即做出?我怎么能强迫他们立即进行?

Why are the request not being made immediately? And how can I force them to be made immediately?

角V1.1.5

推荐答案

我终于找到GitHub上的问题的答案(<一个href=\"https://github.com/angular/angular.js/issues/2442\">https://github.com/angular/angular.js/issues/2442):

The reason

I eventually found the answer in the issues on GitHub (https://github.com/angular/angular.js/issues/2442):

... V1.1.4工作改变使得它被安排在nextTick而不是立即解雇的方式$ HTTP。这意味着,如果你的$ HTTP是从什么计划不会导致一个$摘要火那么你的请求将不会被发送。您可以验证这是你通过点击页面上的几次(任何地方)看到的行为,你会看到你的要求出去。

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.

由于后建议我引发了$消化周期,这引起了我的$ HTTP请求生成要立即解雇。

A Solution

As the post suggested I triggered a $digest cycle, which caused my $http generated requests to be immediately fired.

scope.$apply();

这篇关于角赚不到$ HTTP请求立即的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆