我想在Angular 2中使用* ngFor迭代[object object]。问题是对象不是对象数组而是包含更多对象的对象对象。
{ "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" } }
我知道我们可以使用管道来迭代对象但是我们如何能够从对象进一步迭代意味着数据 – >图片 – > thum:url。
Angular 6.0.0
原文链接:https://www.f2er.com/angularjs/143847.htmlhttps://github.com/angular/angular/blob/master/CHANGELOG.md#610-beta1-2018-06-13
介绍了一个KeyValuePipe
06000
原版的
你可以使用管道
@Pipe({ name: 'keys',pure: false }) export class KeysPipe implements PipeTransform { transform(value: any,args: any[] = null): any { return Object.keys(value)//.map(key => value[key]); } }
<div *ngFor="let key of objs | keys">