I have a service that will make a call to my rest service every 2 minutes. On my service I have the following function
getNotifications(token: string) {
I had a similar need.can be useful to someone and hence writing it here.My Angular version is 9.1.5. I am checking if the user is logged in and sending a http request every 10 minutes until the user is in that component.
const secondsCounter = interval(60000); //Refreshes every 10 minutes
secondsCounter
.pipe(
tap(console.log),
takeWhile(x => this.notificationService.isLoggedIn()),
flatMap(() => this.notificationService.getNotifications(this.token))
).subscribe()