skip to Main Content

I found an API library for Woocommerce and trying to integrate it in Angular.

for fetching categories it looks like this line is needed.

const json = await WooWorker.getCategories();

My service looks like this:

 import { WooWorker } from "api-ecommerce";

  GetAllUsers(): Observable<any> {
    return this.http.get(`${BASEURL}/categories`);
  }

I need to replace this part return this.http.get(${BASEURL}/categories);
with this const json = await WooWorker.getCategories(); since API uses the second way. How will be correct to do it with observable?

2

Answers


  1. GetAllUsers(): Observable<any> {
       return WooWorker.getCategories();
      }
    
    

    Try this way as given above by returning the data from it

    Login or Signup to reply.
  2. You can write it in this way.

    import { WooWorker } from "api-ecommerce";
    import { Observable, of } from 'rxjs';
    
    async GetAllUsers(): Observable<any> {
      const json = await WooWorker.getCategories();
      return of(json);
    }
    

    of is an RxJS operator that converts the input into an observable.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search