25

What's the equivalent of Angular's $q in Angular2? Specifically, I'm looking for $q.when, which allowed you to do something like:

return $q.when(['TestResponse']);
David
  • 15,652
  • 26
  • 115
  • 156

2 Answers2

21
new Promise((resolve, reject) => { 
  if(xxx) {
    resolve('ok');
  } else {
    reject('error');
  }
}).then(x => doSomething())

See also https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise or http://learnangular2.com/es6/promises

qchap
  • 345
  • 6
  • 17
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567
1

You can use the native ES6 Promise. One of the main reasons to make the new angular is ES6 and the upcoming ES7.

Matthias
  • 13,607
  • 9
  • 44
  • 60
E. Abrakov
  • 463
  • 2
  • 6