Reputation: 81
In Angular 9
const headers = new HttpHeaders()
.set('Content-Type', 'application/json; charset=utf-8')
.set('Authorization', this.getToken());
return this.httpClient.get(url,{headers:headers}).pipe(catchError(this.handleError));
can't connect httpheaders. headers not attached with get post put delete call why ?
Upvotes: 1
Views: 1711
Reputation: 461
Here is the correct syntax :
const httpOptions = new HttpHeaders({
'Content-Type': 'application/json',
'Authorization': this.getToken()
});
this.httpClient.get(url, httpOptions).pipe(catchError(this.handleError));
Upvotes: 2
Reputation: 189
You can try this:-
let headers = new HttpHeaders()
headers=headers.set('Content-Type', 'application/json; charset=utf-8')
headers=headers.set('Authorization', this.getToken());
return this.httpClient.get(url,{headers:headers}).pipe(catchError(this.handleError));
Since httpheader and httpparams are kinda immutable in nature so assiging it to the returned object should work.
Upvotes: -1