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

I'm trying to figure out promises ... What is the difference between simply making a $ http request and then executing whether it succeeds (.success ()) and it fails (.fail ()), versus a promise (q = $ q.defer ()) with q.resolve ()?

+3


source to share


2 answers


$http

uses it myself $q

. These services do not work at the same level.

$http.get(url)

returns a promise that can be resolved or rejected. This means that you are using the promise provided by the service ($ http). Inside $http

will call $q.defer()

, then $q.resolve()

or $q.reject()

. This will either call your method .success()

or .fail()

.



$q

is a service for creating your own promise.

Using $q

is a great way to learn about promises, but in your case $http

already does the job for you.

+3


source


Nothing. $http

methods return promises. In short, they can also be linked with then

. success

and fail

are sugar only for permission and rejection then

s.



0


source







All Articles