How to put Http Headers in HttpClient.get()?



ionic-angular  4.0.0-beta.7

Angular 6.1.1 

angular/http  ionic-angular  4.0.0-beta.7

I been trying for the past couple of hours to use the ‘Authorization’ header in my request to the server.

The Angular people (like always <.< ) changed the API yet again so RequestOption doesn’t exist on the http module anymore. How can I use the HttpHeaders?

Here is a snippet of my code!

    const token = sessionStorage.getItem('token');
    if (!token) {
      setTimeout(() => this.getWeather(), 3000);
    const headers = new HttpHeaders({
      'Authorization': `Bearer ${token}`
    const options = {
      headers: headers
    const host = `http://localhost:5000/weather`;
    return this.httpClient.get<IApiResponse<IWeather>>(host, options)

Thanks for the help!


Thank the gods the ionic beta will be Framework agnostic because I am about to trash Angular to hell and stay with Stencil + Ionic or just go/try Vue + ionic.


What version of Ionic are you using?

What version of Angular are you using?

What version of HttpClient are you using?


I am using

ionic-angular 4.0.0-beta.7

Angular 6.1.1 same as angular/http

edited my original post.

This is probably the reason that interceptors exist. See the documentation for an example of writing one to provide authentication tokens.