简体   繁体   中英

Promise chaining, chain promise object

I would like to chain promise object, but the problem that the second then block is executed before the chained promise object got resolved.

service.webService1()
  .then(data => {
    if (data.flag) { // true
      return service.webService2() // returns a promise
    }
    return $q.resolve({})
  })
  .then(data => {
    // some logic
    // data is undefined here, should be the result of
    // service.webService2() call
  })
  .catch(err => {
    // err handling
  })

The problem that I forgot to return my promise in the service.webService2() function. Thanks :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM