角JS调用之前取消$ HTTP调用一个新的$ HTTP [英] Angular JS cancel $http call before calling a new $http

查看:179
本文介绍了角JS调用之前取消$ HTTP调用一个新的$ HTTP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在角JS 1.1.5可以取消previously开始$ HTTP调用。这两个<一个href=\"http://stackoverflow.com/questions/16962232/in-angularjs-how-to-stop-ongoing-http-calls-on-query-change\">link1和<一个href=\"http://stackoverflow.com/questions/13928057/how-do-to-cancel-an-http-request-in-angularjs\">link2给出了它是如何工作的一些解释。

In angular JS 1.1.5 you can cancel previously started $http calls. These two link1 and link2 gives some explanation on how it works.

不过我不明白,如何在实践中使用它。我创建 plnkr 来说明我想达到的目标。

However I can't understand, how to use this in practice. I created plnkr to illustrate what I want to achieve.


  1. 用户有一个链接,他可以点击(因为我们知道,用户往往要做到这一点非常热情地)

  2. 如果用户点击链接,和previous请求尚未完成,它应该被取消,新的请求应(在这个例子中有其他方法可以忽略多次点击,原来的问题是用户输入字段与它NG-变化 - 请求被提出,每次用户变化值 - 每一个关键preSS将火$ HTTP我使用链接,使之简单一点)

正如你在 plnkr 要求火灾看到和被立即取消,但我期待着最后的请求成功。

As you can see in plnkr request fires and gets canceled immediately, but I'm expecting last request to succeed.

我是新来angularjs所以也许我做错了。我gooled一切我能想象,但也有canceler.resolve没有完整的例子()

I'm new to angularjs so probably I'm doing it wrong. I've gooled everything I can imagine, but there are no full examples for canceler.resolve()

谁能帮我这个或指引我正确的方向?

Can anyone help me with this or guide me to right direction?

推荐答案

您需要为每个请求创建一个新的消除,因为一旦它解决了就不能再次使用。

You need to create a new canceler for each request, because once it's resolved it can't be used again.

在这里看到一个更新的plnkr。

这篇关于角JS调用之前取消$ HTTP调用一个新的$ HTTP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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