-
-
Notifications
You must be signed in to change notification settings - Fork 130
/
page-title.service.ts
32 lines (28 loc) · 1 KB
/
page-title.service.ts
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
import { Injectable } from '@angular/core';
import { Title } from '@angular/platform-browser';
import { Store } from '@ngxs/store';
import { RouterState } from '@ngxs/router-plugin';
import { RouterStateData } from '../state/custom-router-state.serializer';
declare var ga: any;
/**
* Service responsible for setting the title that appears above the home and dashboard pages.
*/
@Injectable({
providedIn: 'root',
})
export class PageTitleService {
private readonly defaultTitle;
constructor(private store: Store, private bodyTitle: Title) {
this.defaultTitle = bodyTitle.getTitle() || 'WebApp';
// Automatically set pageTitle from router state data
store.select<any>(RouterState.state).subscribe((routerStateData: RouterStateData) => {
console.log(routerStateData);
bodyTitle.setTitle(
`${Array.from(routerStateData.breadcrumbs.keys())
.reverse()
.join(' | ')} | ${this.defaultTitle}`,
);
ga('send', 'pageview', routerStateData.url);
});
}
}