Edupala

Comprehensive Full Stack Development Tutorial: Learn Ionic, Angular, React, React Native, and Node.js with JavaScript

How to convert promise to observable in rxjs

Note: Not complete yet..
The woocommerce API npm is promise-based. To convert promise to observable I did

  getProducts(page: number): Observable<any> {
    return new Observable((observer) => {
      this.wooCommerce.getAsync('products').then((data) => {
        observer.next(JSON.parse(data.body));
        observer.complete();
      }).catch((error) => {
        console.error(error);
        observer.error();
      });

    });
  }
How to convert promise to observable in rxjs

Leave a Reply

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

Scroll to top