Reputation: 147
I use angular6, i try get json from server through 5 seconds interval.
Its my service:
getExample(): Observable<any> {
console.log('getExample');
return Observable
.timer(0, 5000)
.flatMap(() => this.httpClient.get('https://jsonplaceholder.typicode.com/posts'))
.map((r) => {
return r;
});
}
Please help fix this code.
PS: more simple service worked without problem
Upvotes: 1
Views: 140
Reputation: 191749
RxJS 6 has updated to use pipeable operators. Also, timer imports from a different path. You should import timer
(or interval
in this case) directly and use .pipe
with the operators that you need. Finally, use mergeMap
instead of flatMap
.
import { interval } from 'rxjs';
import { mergeMap, map } from 'rxjs/operators';
return interval(5000).pipe(
mergeMap(() => this.httpClient.get('https://jsonplaceholder.typicode.com/posts')),
map((r) => {
console.log(r);
return r;
})
);
Upvotes: 1