title: Angular2 - How to chain async service calls (http requests) in a component?
body: <p>I have a component which first need to call a service that POST something. Then in the same component I want to wait until the POST is done, to call another service which GETs data.</p>
  
  <p>How can I make the GET call wait for the POST call to finish?</p>
  
  <p>In new-version.component.ts:</p>
  
  <pre class="lang-ts prettyprint-override"><code>private createNewVersion(value) {
      ...
  
      // create new version, then call on all available versions
  
      // POST call
      this._newVersionService.createNewVersion(vnr);
  
      // GET call
      this._versionService.getAvailableVersions(); 
  
      ...
  }
  </code></pre>
  
  <p>In new-version.service.ts:</p>
  
  <pre class="lang-ts prettyprint-override"><code>export class NewVersionService {
  
  response$: Subject&lt;any&gt;;
  
  constructor(private _http: Http) {
      this.response$ = new BehaviorSubject&lt;any&gt;(null);
   }
  
  public createNewVersion(versionNr) {    
      this._http.post('http://localhost:8080/services/' + versionNr, null, {
          method: 'POST',
      })
      .subscribe(response =&gt; {
          this.response$.next(response.status);
      },
      error =&gt; console.error(error));
  }
  </code></pre>
  
  <p>Thanks!</p>