2

我正在使用json-server. localhost:3000它工作正常,我能够在 Angular 中获取数据http.get。我想阅读响应头X-Total-Count,在 angular .subscribe 内。但是我在响应标头中看不到该属性。但 Chrome 控制台显示X-Total-Count: 16.

this.catgoryItems.getAllServices(
    {
        _page: pageIndex || this.pageIndex,
        _limit: limit || this.limit
    })
    .subscribe((response: any) => {
        console.log(response);
        this.dataSource = response.body;
    }, err => {
        console.log(err);
        this.alertService.showError('Error, plz try again later');
    });
4

2 回答 2

7

观察响应和访问标头

http
  .get<any>('url', {observe: 'response'})
  .subscribe(resp => {
    console.log(resp.headers.get('X-Total-Count'));
  });

https://stackoverflow.com/a/48184742/2742156

于 2018-09-19T04:55:30.130 回答
0

你可以使用这个来获取标题

request.get(url).subscribe(data => {
      let count = data.headers.getAll('x-total-count');
}

于 2018-09-19T04:53:19.213 回答