Angular2 Breadcrumb
Installation
npm install angular2-crumbs --save
BreadcrumbModule
1. Import the Import BreadcrumbModule.forRoot()
in the NgModule of your application.
The forRoot
method is a convention for modules that provide a singleton service.
;;;
app.routes
2. Set breadcumbs in const rootRouterConfig: Routes = path: '' redirectTo: 'home' pathMatch: 'full' path: 'home' ... data: breadcrumb: 'Home' path: 'about' ... data: breadcrumb: 'About' path: 'github' ... data: breadcrumb: 'GitHub' children: path: '' ... path: ':org' ... data: breadcrumb: 'Repo List' children: path: '' ... path: ':repo' ... data: breadcrumb: 'Repo' ;
3. Update the markup
- Import the
style.css
into your web page - Add
<breadcrumb></breadcrumb>
tag in template of your application component.
Demo
Customization
Template Customization
You can BYO template using the breadcrumb's ng-content transclude.
Bootstrap breadcrumb:
{{ route.displayName }} {{ route.displayName }}
Materialize Breadcrumb
{{ route.displayName }} {{ route.displayName }}
Dynamic breadcrumbs
Use BreadcrumbService
to set the breadcrumb description dynamically. See full demo example
ngOnInit
Dynamic page titles
Use BreadcrumbService
to subscribe to breadcrumb changes. See full demo example
ngOnInit