import { LocaleService } from './common/i18n'; import { LocalStorageService } from 'angular-2-local-storage'; import { Observable } from 'rxjs/Observable'; import { BaseRequestOptions, Http } from '@angular/http'; import { Component, ViewChild } from '@angular/core'; import { UserService } from './user.service'; import { ActivatedRoute, Router } from '@angular/router'; import { TdNavigationDrawerComponent } from '@covalent/core' @Component({ templateUrl: 'src/app/menu.component.html' }) export class MenuComponent { @ViewChild('mainMenu') mainMenu: TdNavigationDrawerComponent; userFullName: string; constructor(private userService: UserService, private store: LocalStorageService, private $L: LocaleService, private route: ActivatedRoute, private router: Router) { } ngOnInit(): void { this.userService.isLoggedIn().subscribe(authOk => { let isLoggedIn = authOk.valueOf(); if (!isLoggedIn) { this.router.navigateByUrl('public/login'); this.userFullName = null; } else { if (this.route.firstChild == null) { this.router.navigate(['packs']); } this.userFullName = this.store.get("user_full_name"); } } , err => /* Show message */ this.router.navigateByUrl('public/login')); } public logout() { this.userService.logout(); } public closeMenu() { this.mainMenu.close(); } }