这可能是一个简单的答案,但我已经花了好几天试图弄清楚,没有任何成功。
HTTP GET返回此正文响应:
{"members":[{"id":1484,"organization_id":3},{"id":1777,"organization_id":3},{"id":2214,"organization_id":3},{"id":2261,"organization_id":3}]}
我尝试在Angular2中迭代它:
getMembers() {
this.http.get('http://server/user/members')
.map(res => res.json())
.subscribe(
data => this.members = data.members
);
}
如何循环访问成员并阅读其属性? html模板可以很好地完成它:
<li *ngFor="let m of session.members">
{{m.id}}
</li>
答案 0 :(得分:2)
getMembers() {
this.http.get('http://server/user/members')
.map(res => res.json())
.subscribe(
data => {
this.members = data.members;
this.members.forEach(m => console.log(m.id));
});
);
}
答案 1 :(得分:0)
如果您想在模板中迭代它,请尝试:
<li *ngFor="#m of session.members | async">
{{m.id}}
</li>