以下是服务调用
this.http.post(this.apiurl, {'user': this.user}, { responseType: 'json' })
.subscribe((data) => {
this.myRequests = JSON.stringify(data);
const requests = JSON.parse(this.myRequests);
this.Items = requests.filter(function(o) {
return o.detail;
});
},
err => {
console.log(err);
});
}
以下是从服务调用收到的响应:
Array [ {…}, {…} ] --> This is the array of object
以下是数组内容:
0: Object { detail: {'id':'1', 'type': 'service1'} }
1: Object { detail: {'id':'2', 'type': 'service2'} }
下面是 HTML
<ul>
<li *ngFor="let each of Items">
{{each.request_id}}
</li>
</ul>
最佳答案
访问detail.id
属性
<ul *ngFor="let each of Items">
{{each.detail.id}}
</ul>
关于javascript - 如何解析为响应 post 请求而收到的 javascript 对象并将其显示在 Angular 页面中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50924989/