import {Component, Input, OnInit} from '@angular/core'; import {SideMenuItem} from '../menu'; import {ActivatedRoute, Router} from '@angular/router'; import {Subscriber} from "rxjs"; @Component({ selector: 'sidebar', templateUrl: 'sideBar.component.html' }) export class SideBarComponent implements OnInit { @Input() communityId: string = ''; @Input() menuItems: SideMenuItem[] = []; currentParams: any = {}; sub; constructor(private router: Router, private route: ActivatedRoute) { } ngOnDestroy() { if (this.sub instanceof Subscriber) { this.sub.unsubscribe(); } } ngOnInit(): void { this.sub = this.route.queryParams.subscribe(params => { this.currentParams = params; }); } private getCurrentRoute(): string { return this.router.url.split('?')[0]; } isTheActiveMenu(route: string, params: any): boolean { return route === this.getCurrentRoute() && (!params || JSON.stringify(this.currentParams) === JSON.stringify(params)); } }