Skip to main content
added 239 characters in body
Source Link
Aravind
  • 41.7k
  • 16
  • 97
  • 111

YouIt is of type immutable Map so if you assign a new value it will reinitialize the object so you should be doing it as below,

let headers = new HttpHeaders().set('Content-Type', 'application/json')
                               .set('authorization', 'Bearer ' + token);

or

let headers = new HttpHeaders().set('Content-Type', 'application/json');
headers = headers.set('authorization', 'Bearer ' + token);

You should be doing it as below,

let headers = new HttpHeaders().set('Content-Type', 'application/json')
                               .set('authorization', 'Bearer ' + token);

It is of type immutable Map so if you assign a new value it will reinitialize the object so you should be doing as

let headers = new HttpHeaders().set('Content-Type', 'application/json')
                               .set('authorization', 'Bearer ' + token);

or

let headers = new HttpHeaders().set('Content-Type', 'application/json');
headers = headers.set('authorization', 'Bearer ' + token);
Source Link
Aravind
  • 41.7k
  • 16
  • 97
  • 111

You should be doing it as below,

let headers = new HttpHeaders().set('Content-Type', 'application/json')
                               .set('authorization', 'Bearer ' + token);