title: Angular 4 Poll / Stream Data from service within ngOnInit
body: <p>I would like to use AngularJS 4 to stream data from an API.  When I first call the API there is no data, but eventually more results will be returned over a 15 - 30 second period.</p>
  
  <p><strong>Here is my component:</strong></p>
  
  <pre><code>export class ResultsComponent implements OnInit {
      results: Results;
  
      constructor(
          private searchService: SearchService,
          private route: ActivatedRoute
      ) {}
  
      ngOnInit(): void {
  
          this.route.params
              .switchMap((params: Params) =&gt; 
          this.searchService.getResultsObservable(params['searchKey']))
              .subscribe(data =&gt; { this.results = data; });
  }
  </code></pre>
  
  <p><strong>Here are my service calls:</strong></p>
  
  <p>I'm using the Observable call above, but I've included the Promise call as well.</p>
  
  <pre><code>getResults(searchKey: string): Promise&lt;Results&gt; {
      const url = `${this.apiUrl}/${searchKey}/0`;
      return this.http.get(url)
              .toPromise()
              .then(response =&gt; response.json() || {})
              .catch(this.handleError);
  }
  
  getResultsObservable(searchKey: string): Observable&lt;Results&gt; {
      const url = `${this.apiUrl}/${searchKey}/0`;
      return this.http
              .get(url)
              .map(response =&gt; response.json() || {});
  }
  </code></pre>
  
  <p>I believe I need to use the Observable call, but I'm not sure how I need to handle the call within the component.</p>