【发布时间】:2017-09-09 16:29:02
【问题描述】:
我在 Angular 2 中编写了以下代码:
this.http.request('http://thecatapi.com/api/images/get?format=html&results_per_page=10').
subscribe((res: Response) => {
console.log(res);
})
我想在代码中访问响应中的正文字段。 “body”字段以下划线开头,这意味着它是一个私有字段。当我将其更改为 'console.log(res._body)' 时出现错误。
你知道任何可以帮助我的 getter 函数吗?
【问题讨论】:
-
看这里,stackoverflow.com/a/44622319/2803344,然后你可以使用
res.json().results来获取返回的数组。
标签: javascript angular ajax http angular-httpclient