Get custom response header

Ionic v3;

Hello, I can’t get custom header, my code :

 this.http.get(this.apiNotification, {observe: 'response'}).subscribe(
        response => {
            console.log(response.headers.get('unviewed-count'));
        }, error => {
            console.error(error);
         }
 );

But response header have only array with 2 values :

0: {“content-type” => “content-type”}
1: {“cache-control” => “cache-control”}

I can’t see others headers values, do you have any idea ?

Thank’s guys :slight_smile:

i think you should initialise new Httpheaders like this :

let headers: Headers = new Headers();
headers.append('Content-Type', 'application/json');
headers.append('Authorization', 'Bearer {your token}');

this.http.get(this.apiNotification, headers).subscribe(
        response => {
            console.log(response.headers.get('unviewed-count'));
        }, error => {
            console.error(error);
         }
 );

I tried with that code :

import { HttpClient, HttpHeaders, HttpResponse } from '@angular/common/http';

const httpOptions = {
  headers: new HttpHeaders({ 'Content-Type': 'application/json' }),
  observe: 'response'
};

this.http.get(this.apiNotification,httpOptions).subscribe((res: HttpResponse<any>) => {
  console.log(response.headers.get('unviewed-count'));
})

I have same result