Here is my code:
import { HttpClient, HttpErrorResponse, HttpHeaders } from \'@angular/common/http\';
First, you need to add HttpHeaders with HttpClient
import { HttpClient,HttpHeaders } from '@angular/common/http';
your constructor should be like this.
constructor(private http: HttpClient) { }
then you can use like this
let header = new HttpHeaders({ "Authorization": "Bearer "+token});
const requestOptions = { headers: header};
return this.http.get(url, requestOptions)
.toPromise()
.then(data=> {
//...
return data;
});