matrix-dimension/web/app/page-header/page-header.component.ts

36 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-12-15 02:33:32 -05:00
import { Component } from "@angular/core";
import { ActivatedRoute, NavigationEnd, PRIMARY_OUTLET, Router } from "@angular/router";
import { TranslateService } from "@ngx-translate/core";
@Component({
selector: "my-page-header",
templateUrl: "./page-header.component.html",
styleUrls: ["./page-header.component.scss"],
})
export class PageHeaderComponent {
2017-12-15 02:33:32 -05:00
public pageName: string;
constructor(private router: Router, private activatedRoute: ActivatedRoute, public translate: TranslateService) {
this.translate = translate;
2017-12-15 02:33:32 -05:00
this.router.events.filter(ev => ev instanceof NavigationEnd).subscribe((ev: NavigationEnd) => {
let currentRoute = this.activatedRoute.root;
let url = "";
while (currentRoute.children.length > 0) {
let children = currentRoute.children;
children.forEach(route => {
2020-12-28 23:05:45 -05:00
if (route.snapshot.data['breadcrumb']) {
this.translate.get(route.snapshot.data['breadcrumb']).subscribe((res: string) => {route.snapshot.data['breadcrumb'] = res});
}
2017-12-15 02:33:32 -05:00
currentRoute = route;
url += "/" + route.snapshot.url.map(s => s.path).join("/");
if (route.outlet !== PRIMARY_OUTLET) return;
if (!route.routeConfig || !route.routeConfig.data) return;
if (url === ev.urlAfterRedirects.split("?")[0]) this.pageName = route.snapshot.data.name;
2017-12-15 02:33:32 -05:00
});
}
});
}
}