From a9a0d270cb0bdb4aa28a118875cc20bef0ae8929 Mon Sep 17 00:00:00 2001 From: "argiro.kokogiannaki" Date: Fri, 13 Nov 2020 16:34:39 +0000 Subject: [PATCH] [Library | Trunk] Add clearSubscription in layout service git-svn-id: https://svn.driver.research-infrastructures.eu/driver/dnet40/modules/uoa-services-library/trunk/ng-openaire-library/src/app@59846 d315682c-612b-4755-9ff5-7f18f6832af3 --- .../sharedComponents/sidebar/layout.service.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) 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 &&