【发布时间】:2019-02-25 20:41:48
【问题描述】:
我最近正在尝试进入 Angular。 我有一个分页请求。
const myParams = new HttpParams().set('page', page.toString()).set('size', size.toString());
this.http.get<HttpResponse<User[]>>('https://localhost:8443/user/', {
headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
params: myParams,
observe: 'response'
}).suscribe((response: HttpResponse<User[]>) => this.data = response.body);
DB 中的元素总数在X-Total-Count 标头中传输给客户端。我试着这样读:
.suscribe((response: HttpResponse<User[]>) => {
this.data = response.body;
this.totalCount = response.headers.get('X-Total-Count');
});
但这不起作用。事实证明,response.headers 仅包含真实 http-response-headers 的子集。
这就是 headers 对象的样子
"headers": {
"normalizedNames": {},
"lazyUpdate": null
}
我确定 X-Total-Count 已发送。 Firefox devtools 显示它。您能告诉我如何将其包含在响应中吗?
更新
这个问题与被识别为重复的问题有以下不同之处:我没有问过如何检查完整的 httpResponse。我自己想出来的。我一直在问为什么Response的headers属性不完整。
【问题讨论】:
-
很遗憾地通知您,这不是您提到的帖子的复制品。如您所见,我使用了您链接的答案中的方法。
observe: 'response'。我的问题是response.headers不包含 all 后端发送的标头。 -
对不起,你是对的!
标签: angular angular6 angular-httpclient