Is there a better way using RxJS operators to loop over an array returned from an observable than this to emit a new individual ListingItem?
onGetItemData(){
this.dataService.getItemData().subscribe((itemData) =>
{
this.itemDataJSON = itemData;
this.itemDataJSON.forEach(function (value) {
let new_listing = new ListingItem(value.label,value.market,value.name);
console.log(new_listing);
});
});
}
The API returns a single array containing the items, so I am unable to use .map to access itemData.name
//-- DataService --//
getItemData(){
return this.http.get(this._URL, { headers })
.pipe(map((res: Listings) => res.items))
}
flatten
might be what you want.this.http.get(this._URL, { headers }) .pipe(flattten(), map(item => item.name))
– Frasco