import {Component, Inject, Optional} from '@angular/core'; import { Router, NavigationEnd, ActivatedRoute, } from '@angular/router'; import {LoginService} from './services/login-service/login-service'; import {Title} from '@angular/platform-browser'; import {AUTH_ENABLED} from './app.tokens'; import {WarService} from "./services/war-service/war.service"; import {War} from "./models/model-interfaces"; @Component({ selector: 'app-root', templateUrl: 'app.component.html', styleUrls: ['app.component.css'] }) export class AppComponent { defaultTitle: string; wars: War[] = []; constructor(@Optional() @Inject(AUTH_ENABLED) public authEnabled, private loginService: LoginService, private warService: WarService, private activatedRoute: ActivatedRoute, private router: Router, private titleService: Title) { } ngOnInit() { this.defaultTitle = this.titleService.getTitle(); this.router.events .filter(event => event instanceof NavigationEnd) .subscribe(event => { this.setBrowserTitle(); }); this.warService.getAllWars().subscribe((wars) => { this.wars = wars; }) } setBrowserTitle() { let title = this.defaultTitle; let route = this.activatedRoute; // firstChild gibt die Haupt-Kindroute der übergebenen Route zurück while (route.firstChild) { route = route.firstChild; title = route.snapshot.data['title'] || title; } this.titleService.setTitle(title); } logout() { this.loginService.logout(); this.router.navigate(['cc-overview']); return false; } }