I have the following method in an angular service which is working properly
getMyRequests( userId: string){
const headers = new HttpHeaders().set('Authorization', `Bearer ${localStorage.getItem(CONSTS.MIDDLEWARE_TOKEN)}`);
return this.http.post<any>(this.MIDDLEWARE_MY_REQUESTS,{ "userId": userId }, { headers , params: null })
}
However the headers part is set locally in the method, and since it used multiple times in differnt methods within the same service I would like to set it in the service globally I tried the following but it doest work
export class MyService {
headers = new HttpHeaders().set('Authorization', `Bearer ${localStorage.getItem(CONSTS.MIDDLEWARE_TOKEN)}`);
getMyRequests( userId: string){
return this.http.post<any>(this.MIDDLEWARE_MY_REQUESTS,{ "userId": userId }, { this.headers , params: null })
}
I would like to know what is the correct solution for this?