title: Implement polling with angular and rxjs
body: <p>I want to implement polling in my nativescript with angular application. I want to check for instance each second the state of my backend server. I have this service :</p>
  
  <pre><code>@Injectable()
  export class StateService {
  getStatus(): Observable&lt;StateApp&gt; {
          let headers = this.getHeaders();
          return this.http
              .get(BackendService.stateUrl, {
                  headers: headers
              })
              .map(res =&gt; {
                  return res.json() as StateApp
              })
              .catch(this.handleErrors);
  }
  </code></pre>
  
  <p>And then I would like to susbscribe to this service and send a request to the server. In my component in my component I have the following code:</p>
  
  <pre><code>IntervalObservable.create(1000).subscribe(() =&gt; {
              this.statusService.getStatus()
                  .subscribe(
                  (next) =&gt; {
                      this.state = next;
                  };
          });
  </code></pre>
  
  <p>I tried to implement the solution that I read here and that deals with the same issue ( but it's a post from almost 2 years ago) <a href="https://stackoverflow.com/questions/35316583/angular2-http-at-an-interval">Angular2 http at an interval</a> but for instance when I write IntervalObservable.takeWhile it doesn't exist anymore (rxjs version 5.4.3). So I was wondering what is the way of achieving the same result (i.e first time to not wait one second to obtain the result and to stop sending requests when component is destroyed)</p>