title: Angular 5 Add Token to header before posting with httpClient
body: <p>I am using a restapi and it requires that I add a token to the header before I can create a new record.</p>
  
  <p>Right now I have a service to create a new record which looks like this:</p>
  
  <p>service.ts</p>
  
  <pre><code>create(title, text) {
      let headers: HttpHeaders = new HttpHeaders();
      headers = headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
      headers = headers.append('Authorization', token); // Not added yet as this is the reason for the question
      return this.http.post('http://myapi/api.php/posts', {
        title: 'added title',
        text: 'added text'
      }, { headers });
    }
  </code></pre>
  
  <p>app.component.ts</p>
  
  <pre><code>add() {
      this.service.create('my title', 'body text').subscribe(result =&gt; {
        console.log(result);
      });
    }
  </code></pre>
  
  <p>The problem with this is that it won't let me add the new record because it requires a token and in order to get a token I need to run this:</p>
  
  <pre><code>getToken() {
      let headers: HttpHeaders = new HttpHeaders();
      headers = headers.append('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
      return this.http.post('http://myapi/api.php/user', {
        username: 'admin',
        password: 'password'
      }, { headers });
    }
  </code></pre>
  
  <p>My question is...How do I get this two together into one call instead of two...or when is the best way to do this?</p>