hv2-all-in-one/ui/hv2-ui/src/app/navigation/navigation.component.ts

39 lines
1.1 KiB
TypeScript

import { Component } from '@angular/core';
import { BreakpointObserver, Breakpoints } from '@angular/cdk/layout';
import { Observable } from 'rxjs';
import { map, shareReplay } from 'rxjs/operators';
import { TokenService } from '../token.service';
import { NavigationEnd, Router } from '@angular/router';
@Component({
selector: 'app-navigation',
templateUrl: './navigation.component.html',
styleUrls: ['./navigation.component.css']
})
export class NavigationComponent {
public authenticated: boolean
isHandset$: Observable<boolean> = this.breakpointObserver.observe(Breakpoints.Handset)
.pipe(
map(result => result.matches),
shareReplay()
);
constructor(
private breakpointObserver: BreakpointObserver,
private tokenService: TokenService,
private router: Router) {
this.router.events.subscribe((e: any) => {
if (e instanceof NavigationEnd) {
this.authenticated = this.tokenService.checkAuthenticated()
}
})
}
ngOnInit() {
this.authenticated = this.tokenService.checkAuthenticated()
}
}