如何从 Angular http.get 中的 json-server 读取 X-Total-Count?

How to read X-Total-Count from json-server in Angular http.get?

我在 localhost:3000 使用 json-server。它工作正常,我能够在 Angular http.get 中获取数据。我想阅读 header X-Total-Count 内的回复 angular .subscribe。但是我在响应 header 中看不到 属性。但是 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');
    });

你可以用这个

得到header

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

观察响应并访问headers

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

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