What's the equivalent of Angular's $q in Angular2?

∥☆過路亽.° 提交于 2019-11-30 21:42:28

问题


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']);

回答1:


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




回答2:


You can use the native es6 Promise. One of the main reason to make new angular is es6 and nearly comming es7.



来源:https://stackoverflow.com/questions/37719306/whats-the-equivalent-of-angulars-q-in-angular2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!