diff --git a/dashboard/sharedComponents/sidebar/layout.service.ts b/dashboard/sharedComponents/sidebar/layout.service.ts index dec644cc..c5e1646e 100644 --- a/dashboard/sharedComponents/sidebar/layout.service.ts +++ b/dashboard/sharedComponents/sidebar/layout.service.ts @@ -1,5 +1,5 @@ import {Injectable} from "@angular/core"; -import {BehaviorSubject, Observable} from "rxjs"; +import {BehaviorSubject, Observable, Subscriber} from "rxjs"; import {ActivationStart, Router} from "@angular/router"; @Injectable({ @@ -36,8 +36,19 @@ export class LayoutService { private _isFrontPageSubject: BehaviorSubject = new BehaviorSubject(false); private _isSmallScreenSubject: BehaviorSubject = new BehaviorSubject(false); + sub:any; + + ngOnDestroy() { + this.clearSubscriptions(); + } + + clearSubscriptions(){ + if (this.sub instanceof Subscriber) { + this.sub.unsubscribe(); + } + } constructor(private router: Router) { - this.router.events.subscribe(event => { + this.sub = this.router.events.subscribe(event => { if (event instanceof ActivationStart) { let data = event.snapshot.data; if (data['hasSidebar'] !== undefined &&