Git Product home page Git Product logo

ng2-breadcrumb-1's Introduction

ng2-breadcrumb

This component generates a breadcrumb trail as you navigate to child paths using the @angular/router. Each new route & router-outlet is treated as an endpoint, that shows up as a new level in the breadcrumb trail. Its also possible to create a conceptual parent child hierarchy with just sibling routes, using the '%' char when defining a route path. For example the below Routes uses a single router-outlet, but will be 3 levels deep in the breadcrumb trail:

@Routes([
	{ path: '/comp1', component: Component1},
	{ path: '/comp1%comp2', component: Component2},
	{ path: '/comp1%comp2%comp3', component: Component3}
])

Theres a breadcrumbService that allows you to add friendly names for each of your apps route paths (the friendly name will ultimately show up in the breadcrumb trail):

constructor(private breadcrumbService: BreadcrumbService) {
	breadcrumbService.addFriendlyNameForRoute('/comp1', 'Comp 1');
	breadcrumbService.addFriendlyNameForRoute('/comp1%comp2', 'Comp 2');
	breadcrumbService.addFriendlyNameForRoute('/comp1%comp2%comp3', 'Comp 3');
}

For a live example see: https://embed.plnkr.co/H0C1rL2oEM2Bu4XYJNEO/

Dependencies

Requires bootstrap.css (v 3.x.x) for styling of some elements (although the component is fully functional without it).

Install

Install the module via npm:

npm install ng2-breadcrumb --save

Usage

Import the BreadcrumbService and make it available as a global provider when you bootstrap your app:

import {BreadcrumbService} from 'ng2-breadcrumb/ng2-breadcrumb';

bootstrap(App, [
	BreadcrumbService
])

Import both the BreadcrumbComponent & BreadcrumbService into your component and update its list of directives:

import {BreadcrumbComponent, BreadcrumbService} from 'ng2-breadcrumb/ng2-breadcrumb';

@Component({
	directives: [BreadcrumbComponent]
})
class Component {
	...
}

Inject the BreadcrumbService via the components constructor so you can add friendly names for each of your apps routes:

constructor(private breadcrumbService: BreadcrumbService) {
	breadcrumbService.addFriendlyNameForRoute('/home', 'Home Sweet Home');
}

Place the breadcrumb selector in your components html where you added your router-outlet:

<breadcrumb></breadcrumb>
<router-outlet></router-outlet>

Build

To compile the project locally just run the default gulp task (ensure you have gulp install globally to do this):

gulp

ng2-breadcrumb-1's People

Contributors

gmostert avatar

Watchers

James Cloos avatar Kazakh avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.