问题
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