Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

Angular PrimeNG Breadcrumb Component

  • Last Updated : 07 Oct, 2021

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Breadcrumb component in Angular PrimeNG. We will also learn about the properties, events & styling along with their syntaxes that will be used in the code.

Breadcrumb component: It provides the navigation link that is used to link the previous pages the user navigate through & display it in the hierarchy.

Properties:

  • model: It is an array of menuitems to be shown. It is of array data type, the default value is null.
  • home: It is the menuItem configuration for the home icon. It is of MenuItem type, the default value is null.
  • style: It is the inline style of the component. It is of string data type, the default value is null.
  • styleClass: It is the style class of the component. It is of string data type, the default value is null.

Events:

  • onItemClick: It is a callback that is fired when an item is selected.

 



Styling:

  • p-breadcrumb: It is the container element.
  • p-menuitem: It is the menuitem element.
  • p-menuitem-text: It is the label of a menuitem.
  • p-breadcrumb-chevron: It is the chevron element.

Creating Angular application & module installation:

  • Step 1: Create an Angular application using the following command.
ng new appname
  • Step 2: After creating your project folder i.e. appname, move to it using the following command.
cd appname
  • Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

Example 1: This is the basic example that illustrates how to use the Breadcrumb Component. 

app.component.html




<h2>GeeksforGeeks</h2>
<h5>PrimeNG Breadcrumb Component</h5>
<p-breadcrumb [model]="gfg"></p-breadcrumb>

app.module.ts




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { BreadcrumbModule } from "primeng/breadcrumb";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            BreadcrumbModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

 



app.component.ts




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
    this.gfg = [
      { label: "AngularJS" },
      { label: "ReactJS" },
      { label: "HTML" },
      { label: "JavaScript" },
      { label: "PrimeNG" },
    ];
  }
}

Output:

Example 2: In this example, we will know how to use home property in the breadcrumb component and also made the elements itemlist using an HTML template.

app.component.html




<p-breadcrumb
  [model]="[{label: 'A'},{label: 'B'},
       {label: 'C'},{label: 'D'},{label: 'E'}]"
  [home]="home">
</p-breadcrumb>

app.module.ts




import { NgModule } from "@angular/core";
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } 
    from "@angular/platform-browser/animations";
  
import { AppComponent } from "./app.component";
import { BreadcrumbModule } from "primeng/breadcrumb";
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            BreadcrumbModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

app.component.ts




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "my-app",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
    this.home = { icon: "pi pi-home" };
  }
}

Output:

Reference: https://primefaces.org/primeng/showcase/#/breadcrumb




My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!