import { Component } from '@angular/core' ; import { Router } from '@angular/router' ; import { AuthService } from './auth.service' ; @ Component ( { selector : 'app-root' , templateUrl : './app.component.html' , styleUrls : [ './app.component.css' ] } ) export class AppComponent { title = 'nodejsLabs' ; username = '' ; constructor ( private authService , private router ) { } ngOnInit ( ) { this . authService . currenUsername . subscribe ( username => this . username = username ) ; } logout ( ) { this . authService . logout ( ) . subscribe ( ( response ) => { this . authService . removeUserInfo ( ) ; this . router . navigate ( [ 'login' ] ) ; } ) ; } }