I am trying to iterate over objects of object
Here is response json I will get
{
"123445": {
"displayName": "abcd",
"items": [
{
"id": "e7363730-552d-4943-a3b8-082db653fc16",
"name": "xyz",
"displayName": "xyd",
"price": "75",
"quntity": "100"
},
{
"id": "302fda08-502d-4f5a-98b8-cbca34f8e186",
"name": "pqr",
"displayName": "pqr",
"price": "60",
"quntity": "100"
}
]
}
}
Here is what am trying
<div *ngFor="let key of generateKeys(products | async)">
<div *ngFor="let product of products[key].items | async">{{ product | json}}</div>
</div>
and here is funtion which will return keys from products object
generateKeys(obj) {
return obj ? Object.keys(obj) : null
}
But while rendering HTML template it is giving err that
Cannot read property 'items' of undefined
Am I missing something, please suggest.
productsList = [{object1},{object2},{and so on}]Object.keyswhich returns an array :)generateKeysreturns an array then he iterateproducts[key].items which is an array.