如何使用* ngFor迭代對象鍵我想在Angular 2中使用* ngFor迭代[object object]。問題是對象不是對象數(shù)組而是包含更多對象的對象對象。{
"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"
}}我知道我們可以使用管道迭代對象,但我們?nèi)绾文軌驈膶ο筮M(jìn)一步迭代意味著data-> picture-> thum:url。
3 回答

千萬里不及你
TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超9個(gè)贊
我認(rèn)為最優(yōu)雅的方法是使用這樣的javascript Object.keys
:
在Component中將Object傳遞給模板:
Object = Object;
然后在模板中:
<div *ngFor="let key of Object.keys(objs)"> my key: {{key}} my object {{objs[key] | json}} <!-- hier I could use ngFor again with Object.keys(objs[key]) --></div>
- 3 回答
- 0 關(guān)注
- 913 瀏覽
添加回答
舉報(bào)
0/150
提交
取消