From 751497556a7c44159a016342c8eef0195c0d82b4 Mon Sep 17 00:00:00 2001 From: Sercan Yemen Date: Wed, 3 Jan 2018 10:32:15 +0300 Subject: [PATCH] (Contacts App) Fixed: Selected filter is not preserved on route changes --- .../contacts/sidenavs/main/main.component.ts | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/src/app/main/content/apps/contacts/sidenavs/main/main.component.ts b/src/app/main/content/apps/contacts/sidenavs/main/main.component.ts index 262dfa7d..0f6f8957 100644 --- a/src/app/main/content/apps/contacts/sidenavs/main/main.component.ts +++ b/src/app/main/content/apps/contacts/sidenavs/main/main.component.ts @@ -1,26 +1,25 @@ -import { Component, OnInit } from '@angular/core'; +import { Component, OnDestroy } from '@angular/core'; import { ContactsService } from '../../contacts.service'; +import { Subscription } from 'rxjs/Subscription'; @Component({ selector : 'fuse-contacts-main-sidenav', templateUrl: './main.component.html', styleUrls : ['./main.component.scss'] }) -export class FuseContactsMainSidenavComponent implements OnInit +export class FuseContactsMainSidenavComponent implements OnDestroy { user: any; filterBy: string; + onUserDataChangedSubscription: Subscription; constructor(private contactsService: ContactsService) { - this.filterBy = 'all'; - this.contactsService.onUserDataChanged.subscribe(user => { - this.user = user; - }); - } - - ngOnInit() - { + this.filterBy = this.contactsService.filterBy || 'all'; + this.onUserDataChangedSubscription = + this.contactsService.onUserDataChanged.subscribe(user => { + this.user = user; + }); } changeFilter(filter) @@ -28,4 +27,9 @@ export class FuseContactsMainSidenavComponent implements OnInit this.filterBy = filter; this.contactsService.onFilterChanged.next(this.filterBy); } + + ngOnDestroy() + { + this.onUserDataChangedSubscription.unsubscribe(); + } }