I dont get rxjs 6 with angular 6 with interval, switchMap, and map

Tampa picture Tampa · May 6, 2018 · Viewed 31.7k times · Source

I want to update my rxjs code to 6 got I don't get it.

Before I had the below that wouth poll for new data every 5 seconds:

import { Observable, interval } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';

var result = interval(5000).switchMap(() => this._authHttp.get(url)).map(res => res.json().results);

Now...of course, it's broken and the documentation leaves me nowhere to go.

How do I write the above to conform to rxjs 6?

Thanks

Answer

siva636 picture siva636 · May 6, 2018

The code should be something like the following. You need to use the pipe operator.

import { interval } from 'rxjs';
import { switchMap, map } from 'rxjs/operators';

const result = interval(5000).pipe(
switchMap(() => this._authHttp.get(url)),    
map(res => res.results)
)