npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@ngserveio/navigation

v8.1.1

Published

Find more at libraries and examples at [NgServe.io](https://ngserve.io).

Downloads

176

Readme

@ngserveio/navigation

Find more at libraries and examples at NgServe.io.

Read More At: Angular Tutorial - Creating a Navigation Module and Breadcrumb

Running unit tests

Run nx test shared-ui-navigation to execute the unit tests.

See the Video Tutorial on YouTube

Angular Breadcrumbs with @ngserveio/navigation

Breadcrumb

Import the Navigation Module and Configuration

Route Configuration

const CART_LABEL_SERVICE = 'CART_LABEL_SERVICE';

export const ngServeIoFeatureBreadcrumbExampleRoutes: Route[] = [
  {
    path: 'cart',
    component: CrumbSampleComponent,
    data: {
      crumb: {
        providerKey: CART_LABEL_SERVICE,
      } as IBreadcrumbRouteConfig,
    },
  },
  {
    path: '',
    redirectTo: 'cart',
    pathMatch: 'full',
  },
];

Each route which requires a breadcrumb, add to the data property of route crumb which implements the IBreadcrumbRouteConfig. The providerKey shown here maps to the service that will help display the label in the breadcrumb. If the crumb is static, e.g. Home, the default crumb service will display the static label given.

Route Configuration & Registering Services

@NgModule({
  imports: [
    CommonModule,
    NgServeNavigationModule,
    RouterModule.forChild(ngServeIoFeatureBreadcrumbExampleRoutes),
  ],
  providers: [],
  declarations: [CrumbSampleComponent, BreadCrumbExampleComponent],
})
export class NgServeIoFeatureBreadcrumbExampleModule {
  constructor(factory: BreadcrumbFactoryService) {
    factory.registerLabelService(
      CART_LABEL_SERVICE,
      CartBreadcrumbLabelService
    );
  }
}

Import the NgServeNavigationModule. This exposes to the BreadcrumbComponent to the NgServeIoFeatureBreadcrumbExampleModule for consumption.

In the constructor of the NgServeIoFeatureBreadcrumbExampleModule, the BreadcrumbFactoryService registers services to specific to displaying a label for the breadcrumb.

Creating Breadcrumb Label Service

Specific breadcrumb labels services will need to implement the IBreadCrumbLabelService to utilize the getBreadcrumbPath method from the ActivatedRouteSnapshot.

export interface IBreadCrumbLabelService {
  getCrumb(route: ActivatedRouteSnapshot): IBreadCrumb;
}

IBreadcrumb Interface

export interface IBreadcrumb {
  path: string;
  label: Observable<string>;
  icon?: Observable<string>;
}

Cart Label Service

import { getBreadcrumbPath } from '@ngserveio/navigation';

@Injectable({ providedIn: 'root' })
export class CartBreadcrumbLabelService implements IBreadCrumbLabelService {
  constructor(private cartService: CartService) {
    super();
  }

  public getCrumb(route: ActivatedRouteSnapshot): IBreadcrumb {
    return {
      label: this.cartService.cartCount$.pipe(
        map((value) => `Cart (${value})`)
      ),
      path: getBreadcrumbPath(route),
    } as IBreadCrumb;
  }
}

Breadcrumb Component

The responsibility falls upon the consumer of the breadcrumb how each crumb will display. The ng-serve-breadcrumb component allows consumers to define display through a template. Find an example at Breadcrumb Example.

<ng-serve-breadcrumb [itemTemplate]="crumbTemplate">
  <ng-template
    #crumbTemplate
    let-crumb
    let-index="index"
    let-crumbLength="crumbLength"
    let-last="last"
  >
    <a [routerLink]="crumb.path"> {{ crumb.label | async }} </a>
  </ng-template>
</ng-serve-breadcrumb>

Breadcrumb Template Template Source

<div
  *ngLet="{ breadcrumbs: (breadcrumbs$| async) } as data"
  [ngClass]="breadCrumbClass"
>
  <div
    [ngClass]="crumbCssClass"
    *ngFor="let crumb of data.breadcrumbs; let i = index; let isLast = last"
  >
    <ng-container
      [ngTemplateOutlet]="itemTemplate"
      [ngTemplateOutletContext]="{ $implicit: crumb, index: i, last: isLast, crumbLength: data.breadcrumbs.length }"
    >
    </ng-container>
  </div>
</div>

Inputs |Name|Required|Description| |----|--------|-----------| |itemTemplate| Yes | The template required to render the crumb template| |breadCrumbClass| No | The wrapping element css class | |crumbCssClass| No | Each crumb's cssClass |