Open In App

Angular PrimeNG TieredMenu Animation Configuration

Last Updated : 22 Dec, 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 see how to use the TieredMenu Animation Configuration in Angular PrimeNG.

The TieredMenu Component allows a user to make the menu in the form of tiers. The Animation Configuration can be used to control the show and hide animation of the TieredMenu. We can pass the animation configuration to the showTransitionOptions and hideTransitionOptions properties. 

Angular PrimeNG TieredMenu Animation Configuration Properties:

  • showTransitionOptions: It specifies the transition options of the show transition. The default value is .12s cubic-bezier(0, 0, 0.2, 1)”.
  • hideTransitionOptions: This property specifies the transition option of the hide transition. The default value is  “.1s linear”

 

Syntax:

<p-tieredMenu [(ngModel)]="dateValue" 
                 [showTransitionOptions]="..." 
              [hideTransitionOptions]="...">
</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:

 

Example 1: This example describes the basic usage of the TieredMenu Animation Configuration in Angular PrimeNG by setting the showTransitionOptions property to 3000ms.

  • app.component.html

HTML




<h1 style="text-align:center; 
           color:green;">
    GeeksforGeeks
</h1>
<h3 style="text-align:center">
            Angular PrimeNG TieredMenu 
            Animation Configuration
</h3>
<p-tieredMenu [showTransitionOptions]="'3000ms'" 
              [model]="items" #menu 
              [popup]="true">
</p-tieredMenu>
<button #btn type="button" pButton 
             icon="pi pi-fw pi-list" 
             label="Show" 
             (click)="menu.toggle($event)">
</button>


  • app.component.ts

Javascript




import { Component, OnInit, ViewEncapsulation } 
    from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: 'DSA',
  
                items: [
                    {
                        label: 'Stack',
                    },
                    {
                        label: 'Array',
                    },
                    {
                        label: 'Linked List',
                    },
                ],
            },
            {
                label: 'Computer Network',
            },
            {
                label: 'Operating System',
  
                items: [
                    {
                        label: 'Batch OS',
                    },
                    {
                        label: 'Real-Time OS',
                    },
                    {
                        label: 'Time Sharing OS',
                    },
                ],
            },
            {
                label: 'Theory of Computation',
            },
  
            {
                label: 'Exit',
            },
        ];
    }
}


  • 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';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TieredMenuModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

Example 2: This example describes the basic usage of the TieredMenu Animation Configuration in Angular PrimeNG by setting the hideTransitionOptions property to 3000ms.

  • app.component.html

HTML




<h1 style="text-align:center;
           color:green;">
    GeeksforGeeks
</h1>
<h3 style="text-align:center">
        Angular PrimeNG TieredMenu 
        Animation Configuration
</h3>
<p-tieredMenu [hideTransitionOptions]="'3000ms'" #menu 
              [model]="items" 
              [popup]="true">
</p-tieredMenu>
<button #btn type="button" pButton 
             icon="pi pi-fw pi-list" 
             label="hide" 
             (click)="menu.toggle($event)">
</button>


  • app.component.ts

Javascript




import { Component, OnInit, ViewEncapsulation } 
    from '@angular/core';
import { MenuItem } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: 'DSA',
  
                items: [
                    {
                        label: 'Stack',
                    },
                    {
                        label: 'Array',
                    },
                    {
                        label: 'Linked List',
                    },
                ],
            },
            {
                label: 'Computer Network',
            },
            {
                label: 'Operating System',
  
                items: [
                    {
                        label: 'Batch OS',
                    },
                    {
                        label: 'Real-Time OS',
                    },
                    {
                        label: 'Time Sharing OS',
                    },
                ],
            },
            {
                label: 'Theory of Computation',
            },
  
            {
                label: 'Exit',
            },
        ];
    }
}


  • 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';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TieredMenuModule,
        ButtonModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule { }


Output:

 

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



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

Similar Reads