title: Long Polling in Angular 4
body: <p>I need to do API calls to display the progress of something.</p>
  
  <p>I have created a service which does this every 1.5 seconds</p>
  
  <p><strong>Main Component</strong></p>
  
  <pre><code>private getProgress() {
          this.progressService.getExportProgress(this.type, this.details.RequestID);
      }
  </code></pre>
  
  <p><strong>Services.ts</strong></p>
  
  <pre><code>public getExportProgress(type: string, requestId: string) {
      Observable.interval(1500)
          .switchMap(() =&gt; this.http.get(this.apiEndpoint + "Definition/" + type + "/Progress/" + requestId))
          .map((data) =&gt; data.json().Data)
          .subscribe(
          (data) =&gt; {
              if (!data.InProgress)
                  //Stop doing this api call
          },
          error =&gt; this.handleError(error));
  }
  </code></pre>
  
  <p>The call works, but it keeps going. I want to stop doing the API call when the progress is finished (<code>if (!data.InProgress</code>) but I'm stuck on this. </p>
  
  <p>How can I correctly unsubscribe from this observable when <code>if (!data.InProgress)</code>? </p>
  
  <p>Thanks</p>