import {Component, OnDestroy, OnInit} from "@angular/core"; import {LayoutService, SidebarItem} from "../layout.service"; import {Subscription} from "rxjs"; @Component({ selector: 'sidebar-mobile-toggle', template: `
{{activeSidebarItem.name}} - {{activeSidebarItem.subItem.name}}
` }) export class SidebarMobileToggleComponent implements OnInit, OnDestroy { public activeSidebarItem: SidebarItem; private subscriptions: any[] = []; constructor(private layoutService: LayoutService) { } ngOnInit() { this.subscriptions.push(this.layoutService.activeSidebarItem.subscribe(activeSidebarItem => { this.activeSidebarItem = activeSidebarItem; })); } ngOnDestroy() { this.subscriptions.forEach(subscription => { if(subscription instanceof Subscription) { subscription.unsubscribe(); } }); } }