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()?
2 Answers
$http itself uses $q. These both services are not operating at the same level.
$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 is a service to create your own promise.
Using $q is a great way to learn about promises but in your case, $http is already doing that work for you.
2 Comments
Pierre Maoui
The $http legacy promise methods success and error/fail have been deprecated. docs.angularjs.org/api/ng/service/$http#deprecation-notice
$httprequest with$q.defer? If you don't make a request, then that's obviously the difference.