2

I am using json-server at localhost:3000. it is working fine and I am able to get data in Angular http.get. I want to read response header X-Total-Count, inside angular .subscribe. But I can't see that property in the response header. But Chrome console shows that 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');
    });
2

2 Answers 2

7

Observe response and access headers

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

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

Sign up to request clarification or add additional context in comments.

Comments

0

you can get header using this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.