How to send a request with a period of 5 seconds?

Please help to send request to the server with a period of 5 seconds. Now my query works, but only once.


export class TasksService {

 constructor(private to http: HttpClient) { };

 getUserTasks(userId): Observable<any> {
 return this.http.get('' + userId);



ngOnInit() {
 let userId = 1;

 private getUserTasks(userId): void { 
 data => { 
 this.userTasks = JSON.parse(data); 
 console.log('userTasks', this.userTasks);
June 10th 19 at 16:24
1 answer
June 10th 19 at 16:26
setTimeout(action, 5000);
Action is to substitute the right action. In General, feedback from the server is done using sockets and not overloaded bandwidth with unnecessary queries, but I think with your level too early - just for the future.
I would add that to use the socket server must also be configured - katelin_Schul commented on June 10th 19 at 16:29
here's what scares me. Isn't there something simpler to offer? In rxjs there was a special function interval() for such situations. But something I did not get to use it... - Scotty commented on June 10th 19 at 16:32
, - katelin_Schul commented on June 10th 19 at 16:35

Find more questions by tags Angular