Open In App

Angular PrimeNG TieredMenu Inline

Last Updated : 22 Aug, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

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:

  • model: It is an array of menu items. It is of array data type & the default value is null.

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: 

 

  • Run the below command to see the output:
ng serve --open

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

app.component.html




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


app.component.ts




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",
          },
        ],
      },
    ];
  }
}


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 { 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.

app.component.html




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


app.component.ts




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",
          },
        ],
      },
    ];
  }
}


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 { 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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads