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 return promise. promise returned then() adopt it, i.e. fulfills result or reject reason settles.
  • you can throw exception. automatically caught , resulting promise rejected error.

Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -