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.

service:

@Injectable()
export class TasksService {

 constructor(private to http: HttpClient) { };

 getUserTasks(userId): Observable<any> {
 return this.http.get('http://127.0.0.1:8000/app_tasks/user_tasks?user_id=' + userId);
};

}</any>

component:

ngOnInit() {
 let userId = 1;
this.getUserTasks(userId);
}

 private getUserTasks(userId): void { 
this.tasksService.getUserTasks(userId).subscribe(
 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
, ang.overfix.ru/videokurs/bonus4/bonus4_3.html - katelin_Schul commented on June 10th 19 at 16:35

Find more questions by tags Angular