angularjs - How angular promise .then works -
i new angularjs $q , promise, learn if use $http.get(), can promise , can use .then function chainly like
$http.get(url) .then(function(data){}, function(err){}) .then(function(data){}, function(err){}) ..... each return new promise, question how know has been resolved? 1 thing notice if add return function(data){}, next function can return value previous function, mean need give return resolve?
how know has been resolved?
as noticed, promise returned then() resolved after callback executed (which executed when first promise fulfilled). , resolve result callback indeed.
do need give return resolve?
no, if don't return callback, result undefined - regular function calls.
however, in fact have more options build result in callback returning plain value:
- you can
returnpromise. promise returnedthen()adopt it, i.e. fulfills result or reject reason settles. - you can
throwexception. automatically caught , resulting promise rejected error.
Comments
Post a Comment