xxxxxxxxxx
setInterval(()=> { this.myFunc() }, timeIntevalSeconds * 1000);
xxxxxxxxxx
import {Subscription, timer} from 'rxjs';
timerSubscription: Subscription;
ngOnInit(): void {
// timer(0, 10000) call the function immediately and every 10 seconds
this.timerSubscription = timer(0, 10000).pipe(
map(() => {
this.loadData(); // load data contains the http request
})
).subscribe();
}
// don't forget to unsubscribe when the Observable is not necessary anymore
ngOnDestroy(): void {
this.timerSubscription.unsubscribe();
}