argos/dmp-frontend/src/app/shared/components/breadcrumb/breadcrumb.component.ts

39 lines
1.1 KiB
TypeScript
Raw Normal View History

2018-06-27 12:29:21 +02:00
import { Component, OnInit, ViewEncapsulation } from '@angular/core';
import { ActivatedRoute, NavigationEnd, Router } from '@angular/router';
import { BreadCrumbResolverService } from '../../../services/breadcrumb/breadcrumb-resolver.service';
import { BreadcrumbItem } from './definition/breadcrumb-item';
import { Observable } from 'rxjs/Observable';
@Component({
selector: 'app-breadcrumb',
templateUrl: './breadcrumb.component.html',
styleUrls: ['./breadcrumb.component.scss'],
encapsulation: ViewEncapsulation.None
})
export class BreadcrumbComponent implements OnInit {
breadcrumbs$ = this.router.events
.filter(event => event instanceof NavigationEnd)
.distinctUntilChanged()
.flatMap(event => this.buildBreadCrumb(this.activatedRoute.root));
constructor(
public activatedRoute: ActivatedRoute,
private router: Router,
private breadCrumbService: BreadCrumbResolverService
) {
}
ngOnInit() {
}
buildBreadCrumb(route: ActivatedRoute): Observable<BreadcrumbItem[]> {
return this.breadCrumbService.resolve(route);
}
navigate(url, params) {
this.router.navigate([url, params])
}
}