import { Component, OnInit, OnDestroy, Renderer2 } from '@angular/core'; import { NbMenuItem, NbMenuService } from '@nebular/theme'; import { Subscription } from 'rxjs/Subscription'; import { DocsService } from '../../docs/docs.service'; @Component({ selector: 'ngd-header', styleUrls: ['ngd-header.component.scss'], // tslint:disable template: `
Asset 18100Nebular
`, }) // tslint:enable export class NgdHeaderComponent implements OnInit, OnDestroy { isMenuActive: boolean = false; menuItems: NbMenuItem[] = []; private structure: any; private menuSubscription: Subscription; constructor(private service: DocsService, private menuService: NbMenuService, private renderer: Renderer2) { } toggleMenu() { this.isMenuActive = !this.isMenuActive; this.isMenuActive ? this.renderer.addClass(document.body, 'scrolless') : this.renderer.removeClass(document.body, 'scrolless'); } ngOnInit() { this.menuItems = this.service.getPreparedMenu(); this.structure = this.service.getPreparedStructure(); this.menuSubscription = this.menuService.onItemSelect().subscribe(event => { if (this.isMenuActive) { this.toggleMenu(); } }); } ngOnDestroy() { this.renderer.removeClass(document.body, 'scrolless'); this.menuSubscription.unsubscribe(); } }