I need to set some Authorization headers after the user has logged in, for every subsequent request.
To set headers for a particular request,
How about Keeping a Separate Service like follows
import {Injectable} from '@angular/core';
import {Headers, Http, RequestOptions} from '@angular/http';
@Injectable()
export class HttpClientService extends RequestOptions {
constructor(private requestOptionArgs:RequestOptions) {
super();
}
addHeader(headerName: string, headerValue: string ){
(this.requestOptionArgs.headers as Headers).set(headerName, headerValue);
}
}
and when you calling this from another place use this.httpClientService.addHeader("Authorization", "Bearer " + this.tok);
and you will see the added header eg:- Authorization as follows