0

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}

1
  • What behavior are you trying to accomplish here? You just want to make an API call every second? Commented Feb 6, 2017 at 17:51

1 Answer 1

2

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()); }); 
Sign up to request clarification or add additional context in comments.

13 Comments

But now I have an error: EXCEPTION: Error in ./AppComponent class AppComponent - inline template:1:14 caused by: Observable_1.Observable.interval(...).flatMap is not a function
Updated my answer - API seems to have changed, you need to use IntervalObservable nowadays.
What does mean IntervalObservable ? I should import it or declare?
I have done it, but I still have error: EXCEPTION: Error in ./AppComponent class AppComponent - inline template:1:14 caused by: IntervalObservable_1.IntervalObservable.create(...).flatMap is not a function. Should I import flatMap manually?
Possibly, if you don't Import the whole rxjs namespace
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.