S.Hagvin
S.Hagvin

Reputation: 85

Angular 2 HTTP call with interval via Rxjs interval operator

When I try to make http call like this:

return this.http.get(this.url).map(res => res.json());

everything is expected I have correct response without errors, but when I try to make http call with interval (via RxJS operator interval) I have an error.

My code looks:

   return Observable.interval(1000).map(() => {
    return this.http.get(this.url).map(res => res.json());
  });

Error:

ZoneAwareError {__zone_symbol__error: Error: (SystemJS) XHR error (404 Not Found) loading http://localhost:3000/node_modules/rxjs Error: …, __zone_symbol__stack: "(SystemJS) XHR error (404 Not Found) loading http:…alhost:3000/app/home/components/home.component.js", originalErr: ZoneAwareError}

Upvotes: 0

Views: 1574

Answers (1)

Maximilian Riegler
Maximilian Riegler

Reputation: 23506

You have to use .flatMap() and IntervalObservable to get data from another Observable:

return IntervalObservable
    .create(1000)
    .flatMap(() => {
        return this.http.get(this.url).map(res => res.json());
     });

Upvotes: 2

Related Questions