RxJS alternative to doing a Promise.resolve?

谁说我不能喝 提交于 2019-12-06 16:34:16

问题


What is the equivalent in RxJS to Promise.resolve? I know I can do Observable.fromPromise(Promise.resolve(someValue)); but there has to be a cleaner way.


回答1:


Observable.of is what you are looking for (see this plunk):

// You might need to add this import in RxJS versions earlier than 5
import 'rxjs/add/observable/fromArray';

// ... or this line in RxJS 5+
import 'rxjs/add/observable/of';

if (me.groups) {
  return Observable.of(me.groups);
}


来源:https://stackoverflow.com/questions/34616540/rxjs-alternative-to-doing-a-promise-resolve

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