import { Observable } from 'rxjs/Observable'; import { BaseRequestOptions, Http } from '@angular/http'; import { Component, ViewChild } from '@angular/core'; import { UserService } from './user.service'; import { Router } from '@angular/router'; import { TdNavigationDrawerComponent } from '@covalent/core' @Component({ templateUrl: 'src/app/menu.component.html' }) export class MenuComponent { @ViewChild('mainMenu') mainMenu: TdNavigationDrawerComponent; constructor(private userService: UserService, private router: Router) { } ngOnInit(): void { this.userService.isLoggedIn().subscribe(authOk => { let isLoggedIn = authOk.valueOf(); if (!isLoggedIn) { this.router.navigateByUrl('nomenu/login'); } } , err => /* Show message */ this.router.navigateByUrl('nomenu/login')); } public closeMenu() { this.mainMenu.close(); } }