title: Angular2. How can I check if an observable is completed?
body: <p>In my page there is a button that generates a report. That report needs data that is loaded using a http call to a rest endpoint when the page is loaded, but I do not have a guarantee that they are loaded when the user presses the report button.</p>
  
  <p>How can I watch the observable to see if it is completed, and if incomplete, to wait on the action until the http call is completed? Here is some of the code:</p>
  
  <pre class="lang-js prettyprint-override"><code>loadCompanies(): void {
      this._companyService.getCompanies().subscribe(
          response =&gt; {
              this.companiesModel = response;
          },
          err =&gt; console.log(err)
      );
  }
  </code></pre>
  
  
  
  <pre><code>generateReport() {
     // check if observable that loads companies is completed and do the 
     // action using companiesModel.
  } 
  </code></pre>
  
  <p>One option is a flag set in loading companies with values of 'loading' and 'completed', and make a wait in <code>generateReport()</code> until the flag is completed,
  but I would prefer a solution using the <code>Observable</code> API if possible.</p>