I'm attempting to map a JSON object to an observable Interface that I've configured in my angular app, my hope is that once I have it mapped I can use it as an input to loop through an ngFor.
Unfortunately I don't believe I'm configuring either my service correctly, or possible the service call.
I get the json object returned as a single object but the ngFor does not properly loop through the results returned, any assistance in pointing out what I may be overlooking would be greatly appreciated.
// Interface I am trying to access
export interface IProduct {
name: string;
description: string;
price: number;
category: string;
image: string;
}
// Service I am attempting to call
private productList = new BehaviorSubject<IProduct[]|null>(null);
productListChanges$ = this.productList.asObservable();
constructor(private http: HttpClient) { }
getProds(): Observable<IProduct[]> {
this.productList.next(null);
return this.http.get<IProduct[]>
('http://localhost:4200/assets/data/products.json')
.pipe(
tap(data => this.productList.next(data)),
);
}
// Call for the service
productsList: IProduct[] = [];
this.productService.getProds().subscribe((response: any) => {
this.productsList = response.products[0] as IProduct[];
console.log(this.productsList);
});
// Attempt to use ngFor with obtained object
<app-product *ngFor="let product of productsList" [prod]="product" ></app-product>
// Console log from the service call outputs the following