Answer the question
In order to leave comments, you need to log in
How to make a periodic request to the server in Angular?
There is a page with some data that is updated every n time on request from the http service, sometimes updated on request (with time n being reset). Now this is done through setInterval and clearInterval. There are suspicions that there is a more beautiful and understandable way.
Plus, it is required to update the data in time n only after the completion of the current request.
Thank you all for future advice.
ps Angular 7+
Answer the question
In order to leave comments, you need to log in
More or less like this:
import { interval } from 'rxjs';
import { switchMap } from 'rxjs/operators';
const requests$ = interval(300).pipe(
switchMap(() => http.get('path'))
)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question