Having Api call each 5 min in Angular application for that used interval(10000*30).subscirbe. Now want pause the subscrition when browser tab is inactive and resume when active.
Tried below code but not working when 2 time broswer window in inactive. Api called after each 5 mins with below code and its working fine
Angular 12 and Rxjs lib is used.
const sourceInterval = interval(1000 * 30);
this.subscription = sourceInterval.subscribe(val => {
//api call to get notification
});
@HostListener('document:visibilitychange', ['$event'])
visibilitychange() {
if (document.hidden){
this.subscription.unsubscribe();
} else {
// here i want make api call again
tired below code to make api call again but not worked as expected
const sourceInterval = interval(1000 * 30);
this.subscription = sourceInterval.subscribe(val => {
//api call to get notification
});
}
}