以角度5迭代JSON对象响应

时间:2018-05-11 14:08:20

标签: json angular5

我有一个来自REST响应的JSON对象,它希望循环其项目并在UI中显示,这是响应的结构:

 {"Items":
    {"releases":
    [{"last":"365147","first":"365987","relNo":"1","files":[{"fileId":"1","url":"http://....."},{"fileId":"2","url":"http://....."}}],"publish":"Yes"},{"last":"365147","first":"365987","relNo":"2","files":[{"fileId":"1","url":"https://...."},{"fileId":"2","url":"http://....."},{"fileId":"3","url":"...."},{"documentId":"4","url":"http://....."}],"publish":"No"}]}

关于服务我这样做:

this.myService.getDetails(id).subscribe (data => {  
      this.items = data;
      console.log (JSON.stringify(this.items));
    })

1 个答案:

答案 0 :(得分:0)

在您的模板中,您需要一个ngFor。好像你的组件中有一个名为items的变量,所以你需要这样的东西:

<div *ngFor="let item of items">
    {{item.releases}} // or item.whatever field you would like to access
</div>