I'm trying to get a handle on the Angular $q
service and its related objects and APIs. When I look at the objects in my console I see:
var deferred = $q.defer()
...(and then from console inspection)...
$q: Object {defer: function, reject: function, when: function, all: function}
deferred: Object {resolve: function, reject: function, notify: function, promise: Object}
deferred.promise: Object {then: function, catch: function, finally: function}
It raises a few questions:
- What's the difference between
$q.reject()
anddeferred.reject()
? When to use each? - What's the relationship between the
errorFn
indeferred.promise.then(successFn, errorFn)
and thecatchFn
indeferred.promise.catch(catchFn)
? - If I have a bunch of nested promises and an error occurs, will the outermost
catch()
function always be called? What if one of the nested promises also has a catch function defined? Will that catch prevent the outermost catch from executing?
Thanks.