import { AuthenticationService } from '../user-services'; import { Subscription } from 'rxjs' import { Component, EventEmitter, Output, OnInit, OnDestroy } from '@angular/core'; import { Router } from '@angular/router'; import { Utils } from '../shares'; @Component({ selector: 'app-nav-toolbar', templateUrl: './nav-toolbar.component.html', styleUrls: ['./nav-toolbar.component.css'] }) export class NavToolarComponent implements OnInit, OnDestroy { isExpanded = false; isAuth = false; isAdmin = false; currentUserName = ""; authSubscription: Subscription = new Subscription; @Output() toggleEvent: EventEmitter = new EventEmitter(); constructor(private authService: AuthenticationService, private router: Router) { } ngOnInit() { this.authSubscription = this.authService.authChange.subscribe(currentUser => { this.isAuth = Utils.getIsAuth(); this.isAdmin = Utils.getIsAdmin(); this.currentUserName = currentUser; }); } ngOnDestroy() { if (this.authSubscription) { this.authSubscription.unsubscribe(); } } onHome() { this.router.navigate(['/home/concessionvalidation']); } onToggle() { this.isExpanded = !this.isExpanded; this.toggleEvent.emit(this.isExpanded); } onLogout() { this.authService.logout(); this.router.navigate(['/login']); } }