G
G
Gleb2019-03-26 16:12:51
Angular
Gleb, 2019-03-26 16:12:51

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

2 answer(s)
D
Dmitry Luzanov, 2019-03-26
@dmitry_luzanov

More or less like this:

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

const requests$ = interval(300).pipe(
  switchMap(() => http.get('path'))
)

V
Vladimir, 2019-03-27
@Casufi

https://www.apollographql.com/docs/angular/basics/...
https://www.apollographql.com/docs/apollo-server/f...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question