title: Angular 5 pass headers properly in http get requests
body: <p>so initially i was using the deprecated HttpModule for my api requests but i'm using the HttpClientModule now and having issues with passing headers correctly. i've got a function that calls api to get some data...this is what i had initially with HttpModule</p>
  
  <blockquote>
    <p>service.ts</p>
  </blockquote>
  
  <pre><code>export class userService {
    //using HttpModule
    getCurrentProfile() {
      let v = this.page_header();
      return this.http.get(this.userProfileUrl, {headers: headers})
        .toPromise()
        .then(response =&gt; response.json())
        .catch(this.handleError);
    };
  
    //using HttpClientModule
    getCurrentProfile() {
      let headers = new HttpHeaders();
      return this.http.get(this.userProfileUrl, {headers: headers})
        .toPromise()
        .then(response =&gt; response.json())
        .catch(this.handleError);
    };
  
    private page_header() {
      let data = localStorage.getItem('auth_token');
      let headers = new Headers();
      let opt: RequestOptions;
      headers.append('Authorization', 'JWT ' + data);
      opt = new RequestOptions({ headers: headers });
      return opt;
    }
  }
  </code></pre>
  
  <blockquote>
    <p>component.ts</p>
  </blockquote>
  
  <pre><code>getStoreProfile() {
   //using HttpModule
   this.userSrv.getCurrentProfile().then(response =&gt; {
     localStorage.setItem('store', JSON.stringify(response));
     this.profile = JSON.parse(localStorage.getItem('store'));
   }).catch(err =&gt; this.error = err)
  
   //using HttpClientModule
   this.userSrv.getCurrentProfile().subscribe(res =&gt; {
    let data = res;
    localStorage.setItem('store', JSON.stringify(res));
    this.profile = JSON.parse(localStorage.getItem('store'));
  })
  </code></pre>
  
  <p>}
  So initailly it all worked with HttpModule but now with HttpClientModule i get errro</p>
  
  <pre><code>detail:"Authentication credentials were not provided."
  </code></pre>
  
  <p>How am i to pass headers correctly using HttpClientModule.</p>