app.component.ts
1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { Component, OnInit } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import { RoutePartsService } from './services/route-parts/route-parts.service';
import { Router, ActivatedRoute, NavigationEnd } from '@angular/router';
import { Title } from '@angular/platform-browser';
@Component({
selector: 'app-root',
template: '<router-outlet></router-outlet>'
})
export class AppComponent implements OnInit{
private appTitle: string;
private pageTitle: string;
constructor(translate: TranslateService,private routePartsService: RoutePartsService,
private router: Router,
public title: Title,
private activeRoute: ActivatedRoute) {
translate.addLangs(['en', 'fr']);
translate.setDefaultLang('en');
const browserLang: string = translate.getBrowserLang();
translate.use(browserLang.match(/en|fr/) ? browserLang : 'en');
}
ngOnInit() {
this.appTitle = 'BO-LIVEBILIANBET';
this.pageTitle = '';
this.changePageTitle();
}
changePageTitle() {
this.router.events.filter(event => event instanceof NavigationEnd).subscribe((routeChange) => {debugger
var routeParts = this.routePartsService.generateRouteParts(this.activeRoute.snapshot);
if (!routeParts.length)
return this.title.setTitle(this.appTitle);
this.pageTitle = routeParts
.reverse()
.map((part) => part.title)
.reduce((partA, partI) => { return `${partA} > ${partI}` });
this.pageTitle += ` | ${this.appTitle}`;
this.title.setTitle(this.pageTitle);
});
}
}