The structure of the JSON file is as follows:
localjson.json
{
"Product" :{
"data" : [
{ "itemID" : "1" , "name" : "Apple" , "qty" : "3" },
{ "itemID" : "2" , "name" : "Banana" , "qty" : "10" }
]
} }
To retrieve an item by its ID, I have the following function:
getfruits(itemID: string) {
return this.http.get<Array<Fruits>>('assets/localjson.json')
.pipe(
map((items: Array<any>) => {
return items.find((item: Fruits) => {
return item.itemID=== itemID;
});
})
);
}
Fruits.ts
export class Fruits{
itemID: string;
name: string;
qty: string;
}
An error message stating TypeError: items.find is not a function is displayed.