Angular JS $ http.success()vs $ q.resolve()? [英] Angular JS $http.success() vs $q.resolve()?

查看:69
本文介绍了Angular JS $ http.success()vs $ q.resolve()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出承诺...简单地制作一个$ http请求,然后根据是否成功(.success())&它失败了(.fail()),与使用q.resolve()的promise(q = $ q.defer())相比?

I am trying to figure out promises... What is the difference between simply making an $http request, then acting upon whether is what successful (.success()) & it failing (.fail()), in comparison to a promise (q = $q.defer()) with q.resolve()?

推荐答案

$ http 本身使用 $ q 。这两种服务都没有在同一级别运行。

$http itself uses $q. These both services are not operating at the same level.

$ http.get(url)返回一个承诺可以解决或拒绝。这意味着您正在使用服务提供的承诺($ http)。在内部, $ http 将调用 $ q.defer(),然后 $ q.resolve () $ q.reject()。这将调用您的 .success() .fail()方法。

$http.get(url) returns a promise that can be resolved or rejected. It means that you are using a promise delivered by a service ($http). Internally, $http will call $q.defer(), then $q.resolve() or $q.reject(). This will call either your .success() or .fail() method.

$ q 是一项创建自己承诺的服务。

$q is a service to create your own promise.

使用 $ q 是了解承诺的好方法,但在您的情况下, $ http 已经为您完成了这项工作。

Using $q is a great way to learn about promises but in your case, $http is already doing that work for you.

这篇关于Angular JS $ http.success()vs $ q.resolve()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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