To convert Promise to Observable in Angular, you can “use the from() function from the rxjs library.”
To work with the rxjs library, you need to install it first if you have not installed it!
npm install rxjs --save
Import the rxjs library like this:
import { from } from 'rxjs';
Use the from() function to convert a promise to an observable:
import { from } from 'rxjs'
const myPromise = new Promise((resolve, reject) => {
setTimeout(() => {
resolve('Promise resolved');
}, 2000);
});
const myObservable = from(myPromise);
myObservable.subscribe({
next: (v) => console.log(v),
error: (e) => console.error(e),
complete: () => console.info('complete')
});
Output
When the promise resolves, the Observable will emit the data and the subscriber’s callback will be executed.
Note that a Promise will be completed once resolved or rejected, meaning the Observable converted from it will also be completed after emitting the value or error.
If you want to work with Observables that emit multiple values over time, you might want to consider other creation functions or operators from rxjs.
That’s it!

Krunal Lathiya is a seasoned Computer Science expert with over eight years in the tech industry. He boasts deep knowledge in Data Science and Machine Learning. Versed in Python, JavaScript, PHP, R, and Golang. Skilled in frameworks like Angular and React and platforms such as Node.js. His expertise spans both front-end and back-end development. His proficiency in the Python language stands as a testament to his versatility and commitment to the craft.