Open In App

Angular PrimeNG TieredMenu Properties

Last Updated : 31 Oct, 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, we will learn how to use the TieredMenu Properties in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The TieredMenu component allows a user to make the menu in the form of tiers. There are various properties provided by Angular PrimeNG, which are described below.

Angular PrimeNG TieredMenu Properties:

  • model: It is an array of menu items. It is of array data type & the default value is null.
  • popup: It defines if the menu would be displayed as a popup. It is of the boolean data type & the default value is false.
  • appendTo: It specifies the target element to attach the overlay & the valid values are “body” or a local ng-template variable of another element. It is of array data type & the default value is null.
  • style: It sets an inline style of the component. It is of string data type & the default value is null.
  • styleClass: It sets the style class of the component. It accepts the string data type & the default value is null.
  • baseZIndex: It is a base zIndex value to use in layering. It accepts the number as the input data type & the default value is 0.
  • autoZIndex: It specifies whether to automatically manage the layering. It is of the boolean data type & the default value is true.
  • autoDisplay: It specifies whether to show a root submenu on mouseover. It is of the boolean data type & the default value is false.
  • showTransitionOptions: It shows transition options to show the animation. It accepts the string data type & the default value is .12s cubic-bezier(0, 0, 0.2, 1).
  • hideTransitionOptions: It shows transition options to hide the animation. It accepts the string data type & the default value is .1s linear.

 

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:

 

  • To run the above file run the below command:
ng serve --save

Example 1: This is the basic example that shows how to use Angular PrimeNG TieredMenu Properties.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angualar PrimeNG TieredMenu Properties</h5>
<p-tieredMenu [model]="gfg"></p-tieredMenu>


  • app.component.ts:

Javascript




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:

Javascript




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: This is another basic example that shows how to use Angular PrimeNG TieredMenu Properties.

  • app.component.html:

HTML




<h2 style="color: green">GeeksforGeeks</h2>
<h5>
    Angular PrimeNG TieredMenu Properties
</h5>
  
<button #btn type="button"
        pButton label="GfG courses"
        (click)="geeks.toggle($event)"
        class="p-button-success"
        icon="pi pi-code">
</button>
  
<p-tieredMenu #geeks [model]="gfg"
                     [popup]="true">
</p-tieredMenu>


  • app.component.ts:

Javascript




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:

Javascript




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:

 

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



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

Similar Reads