Abhishek Singh
Abhishek Singh

Reputation: 11

getting response undefined in angular

I want to fetch this data from rest api but when i tried to console.log(response) i am getting undefined value. what should i do ? api is sending data and i have checked it in my network tab in developer tool.

getProductList() : Observable<Product[]>{
    return this.httpClient.get<GetResponse>(this.baseUrl).pipe(
      map(response => response._embedded.products),
      tap((response) => console.log("Response:"+response))
    );
   } 

interface GetResponse{
    _embedded:{
      products: Product[];
    }
}

JSON Data Format

Upvotes: 0

Views: 908

Answers (1)

Sajeetharan
Sajeetharan

Reputation: 222522

You probably need to access Product?

map(response => response._embedded.product)

and interface

interface GetResponse{
    _embedded:{
      product: Product[];
    }
}

Upvotes: 1

Related Questions