1

enter image description hereI am using angular2 service to get data response from yii2 api. In browser network tab it showing all required response but when I am trying to get it directly from component like

response.headers.get('X-Pagination-Page-Count') 

Then it's not showing anything. except only showing content-type in response header via code. but can't get a function response. below is my service function.

getResponse(endpointUrl: string): Observable<any> {

    const url = url;

    return this._http.get(url)
        .catch((err) => this._handleError(err))
        .take(1)
        .map((res: Response) => res);
}

this is response image.

Anil Kumar
  • 701
  • 11
  • 28
  • Do you send your requests to your own server? If yes, take a look if you set the `Access-Control-Expose-Headers` attribute. It should contain your custom headers. – Armin Nov 26 '17 at 16:35
  • @Armin I tried all method like sending all options headers.append('Content-Type', 'application/json'); headers.append('Access-Control-Expose-Headers', '*'); headers.append('Access-Control-Expose-Headers', 'X-Pagination-Current-Page'); headers.append('Access-Control-Expose-Headers', 'X-Pagination-Total-Count'); still getting same response, No Luck – Anil Kumar Nov 26 '17 at 16:39
  • Not sending, you have to add it to the backend. – Armin Nov 26 '17 at 16:49
  • Please check I have added response snapshot with query above. – Anil Kumar Nov 26 '17 at 16:53
  • for me, the problem wasn't with angular but with the server that answered my requests. Take a look at the backend and make sure you set the `Access-Control-Expose-Headers` attribute. – Armin Nov 26 '17 at 16:57

0 Answers0