title: Call REST repeatedly in Angular (5)
body: <p>I need create service which will be consume data from long-polling rest service in my backend. When I call this service, backend wait until it has data to send or timeout is expired and send just empty object.</p>
  
  <p>In angular I want service which starts when application is completely loaded, and will be running in background and push data to subjects which I observer.</p>
  
  <p>Can tell me what is the best practice or show me example how to should this service in angular looks like?</p>
  
  <p>Here is my try but it nor call rest on start:</p>
  
  <pre><code>@Injectable()
  export class PollingService {
  
    private url: string;
  
    constructor(private http: HttpClient, private fooService: FooService) {
      this.url = 'http://localhost:8080/api/poll';
      this.startPolling();
    }
  
    startPolling() {
      this.http.get&lt;any&gt;(this.url)
        .map(pollData =&gt; {
          console.log('poll data', pollData);
          this.fooService.mySubject.next(pollData);
          if (pollData)
            this.startPolling();
        });
    }
  }
  </code></pre>