Open In App

Angular PrimeNG TieredMenu Inline

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, will see how to use the TieredMenu Inline in Angular PrimeNG.

TieredMenu Component allows a user to make the menu in the form of tiers. The TieredMenu inline allows users to have nested menu items within the same line.



Angular PrimeNG TieredMenu Inline Properties:

Syntax:



<p-tieredMenu 
    [model]="gfg">
</p-tieredMenu>

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: After complete installation, it will look like the following: 

 

ng serve --open

Example 1: Below is the example code that illustrates the use of Angular PrimeNG TieredMenu Inline.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG TieredMenu Inline</h5>
<p-tieredMenu 
        [model]="gfg">
</p-tieredMenu>




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
    this.gfg = [
      {
        label: "JavaScript",
        items: [
          {
            label: "JavaScript1",
            items: [
              {
                label: "JavaScript1.1",
              },
              {
                label: "JavaScript1.2",
              },
            ],
          },
          {
            label: "JavaScript2",
          },
          {
            label: "JavaScript3",
          },
        ],
      },
      {
        label: "HTML",
        items: [
          {
            label: "HTML 1",
          },
          {
            label: "HTML 2",
          },
        ],
      },
      {
        label: "Angular",
  
        items: [
          {
            label: "Angular 1",
          },
          {
            label: "Angular 2",
          },
        ],
      },
    ];
  }
}




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

Output:

 

Example 2: Below is another example code that illustrates Angular PrimeNG TieredMenu Inline using some different item values.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>
    Angular PrimeNG TieredMenu Inline
</h5>
<p-tieredMenu 
        [model]="gfg">
</p-tieredMenu>




import { Component } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
})
export class AppComponent {
  gfg: MenuItem[];
  
  ngOnInit() {
    this.gfg = [
      {
        label: "Placement - Self Paced",
        items: [
          {
            label: "Batch1",
            items: [
              {
                label: "Batch1.1",
              },
              {
                label: "Batch1.2",
              },
            ],
          },
          {
            label: "Batch2",
          },
          {
            label: "Batch3",
          },
        ],
      },
      {
        label: "Gate Preparation",
        items: [
          {
            label: "Batch1",
          },
          {
            label: "Batch2",
          },
        ],
      },
      {
        label: "C++ STL",
  
        items: [
          {
            label: "Batch1",
          },
          {
            label: "Batch2",
          },
        ],
      },
    ];
  }
}




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

Output:

 

Reference: https://primefaces.org/primeng/tieredmenu


Article Tags :