-import { Injectable, OnDestroy } from '@angular/core';
+import { Injectable, NgZone, OnDestroy } from '@angular/core';
import { BehaviorSubject, interval, Subscription } from 'rxjs';
-import { ServicesModule } from './services.module';
@Injectable({
- providedIn: ServicesModule
+ providedIn: 'root'
})
export class RefreshIntervalService implements OnDestroy {
private intervalTime: number;
// Observable streams
intervalData$ = this.intervalDataSource.asObservable();
- constructor() {
+ constructor(private ngZone: NgZone) {
const initialInterval = parseInt(sessionStorage.getItem('dashboard_interval'), 10) || 5000;
this.setRefreshInterval(initialInterval);
}
if (this.intervalSubscription) {
this.intervalSubscription.unsubscribe();
}
- this.intervalSubscription = interval(this.intervalTime).subscribe(() =>
- this.intervalDataSource.next(this.intervalTime)
- );
+ this.ngZone.runOutsideAngular(() => {
+ this.intervalSubscription = interval(this.intervalTime).subscribe(() =>
+ this.ngZone.run(() => {
+ this.intervalDataSource.next(this.intervalTime);
+ })
+ );
+ });
}
getRefreshInterval() {