I want to iterate [object object] using *ngFor in Angular 2.
The problem is the object is not array of object but object of object which contains further objects.
{
"data": {
"id": 834,
"first_name": "GS",
"last_name": "Shahid",
"phone": "03215110224",
"role": null,
"email": "test@example.com",
"picture": **{ <-- I want to get thumb: url but not able to fetch that**
"url": null,
"thumb": {
"url": null
}
},
"address": "Nishtar Colony",
"city_id": 2,
"provider": "email",
"uid": "test@example.com"
}
}
I know we can use pipe to iterate the object but how we can iterate further from object to object means data->picture->thum:url.
Angular 6.0.0
https://github.com/angular/angular/blob/master/CHANGELOG.md#610-beta1-2018-06-13
introduced a
KeyValuePipe
original
You can use a pipe
See also How to iterate object keys using *ngFor?
You have to create custom pipe.
And then use it in your *ngFor
i would do this:
I know this question is already answered but I have one solution for this same.
You can also use
Object.keys()
inside of*ngFor
to get required result.I have created a demo on stackblitz. I hope this will help/guide to you/others.
CODE SNIPPET
I think the most elegant way to do that is to use the javascript
Object.keys
like this:in the Component pass Object to template:
then in the template: