Categories
Angular Answers

How to convert a promise to an observable with Rxjs?

Spread the love

Sometimes, we want to convert a promise to an observable with Rxjs.

In this article, we’ll look at how to convert a promise to an observable with Rxjs.

How to convert a promise to an observable with Rxjs?

To convert a promise to an observable with Rxjs, we can use the from function.

For instance, we write

import { from } from "rxjs";

//...

const observable = from(promise);

to call from with the promise we want to convert to an observable.

A new observable will be returned and it outputs the resolve value of the promise.

Conclusion

To convert a promise to an observable with Rxjs, we can use the from function.

By John Au-Yeung

Web developer specializing in React, Vue, and front end development.

Leave a Reply

Your email address will not be published. Required fields are marked *