From d96b69f4ca8eac83140b3b451f59621aed2bb517 Mon Sep 17 00:00:00 2001 From: Danijel Andjelkovic Date: Wed, 16 Mar 2022 18:16:56 +0100 Subject: Dodao naslove za sve strane, i zapoceo my-datasets. --- frontend/src/app/app.component.ts | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'frontend/src/app/app.component.ts') diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 9d6b2f11..f5ae5786 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -1,10 +1,37 @@ -import { Component } from '@angular/core'; +import { Component, OnInit } from '@angular/core'; +import { Title } from '@angular/platform-browser'; +import { Router, NavigationEnd, ActivatedRoute } from '@angular/router'; +import { filter, map } from 'rxjs'; @Component({ selector: 'app-root', templateUrl: './app.component.html', styleUrls: ['./app.component.css'] }) -export class AppComponent { - title = 'frontend'; +export class AppComponent implements OnInit { + + constructor(private router: Router, private titleService: Title) { } + + ngOnInit() { + this.router.events + .pipe( + filter((event) => event instanceof NavigationEnd), + map(() => { + let route: ActivatedRoute = this.router.routerState.root; + let routeTitle = ''; + while (route!.firstChild) { + route = route.firstChild; + } + if (route.snapshot.data['title']) { + routeTitle = route!.snapshot.data['title']; + } + return routeTitle; + }) + ) + .subscribe((title: string) => { + if (title) { + this.titleService.setTitle(`${title} - Igrannonica`); + } + }); + } } -- cgit v1.2.3