Open In App

Angular PrimeNG Menu Animation Configuration

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. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Menu Animation Configuration.

The Menu component is used to make a component that contains some information & supports either static or dynamic positioning. The Menu Animation Configuration allows us to configure the default animation of opening and closing the menu.



Menu Animation Configuration properties:

 



Syntax:

<p-menu
    [showTransitionOptions]="'...'"
    [hideTransitionOptions]="'...'"
    #menu
    [model]="..."
    [popup]="..."
>
</p-menu>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new geeks_angular

Step 2: After creating your project folder i.e. geeks_angular, move to it using the following command.

cd geeks_angular

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following:

 

Steps to run the above file: Run the below command

ng serve --save

Example 1: Below is the example code that illustrates the use of the Angular PrimeNG Menu Animation Configuration. This example shows a menu with different animations.




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Menu Animation Configuration</h3>
<button
    type="button"
    pButton
    pRipple
    icon="pi pi-bars"
    label="Show"
    (click)="menu.toggle($event)">
</button>
<p-menu
    #menu
    [popup]="true"
    [showTransitionOptions]="'1s ease-in-out'"
    [hideTransitionOptions]="'0.5s linear'"
    [model]="items">
</p-menu>




import { Component, OnInit, ViewEncapsulation } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
  
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: "Data Structures",
                items: [
                    {
                        label: "Linked List",
                        items: [
                            {
                                label: "Singly Linked List"
                            },
                            {
                                label: "Doubly Linked List"
                            }
                        ]
                    },
                    {
                        label: "Trie"
                    },
                    {
                        label: "Array"
                    }
                ]
            },
            {
                label: "Algorithms",
                items: [
                    {
                        label: "Sorting"
                    },
                    {
                        label: "Searching"
                    }
                ]
            },
            {
                label: "Development",
  
                items: [
                    {
                        label: "Android"
                    },
                    {
                        label: "Web development"
                    }
                ]
            }
        ];
    }
}




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

Output:

 

Example 2: Below is another example that illustrates the use of the Angular PrimeNG Menu Animation Configuration. In the following example, we have a menu with animation which is turned off.




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Menu Animation Configuration</h3>
<button
    type="button"
    pButton
    pRipple
    icon="pi pi-bars"
    label="Show"
    (click)="menu.toggle($event)">
</button>
<p-menu
    #menu
    [popup]="true"
    [showTransitionOptions]="'0s'"
    [hideTransitionOptions]="'0s'"
    [model]="items">
</p-menu>




import { Component, OnInit, ViewEncapsulation } from "@angular/core";
import { MenuItem } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styleUrls: ["./app.component.css"]
})
  
export class AppComponent {
    items: MenuItem[];
  
    ngOnInit() {
        this.items = [
            {
                label: "Data Structures",
                items: [
                    {
                        label: "Linked List",
                        items: [
                            {
                                label: "Singly Linked List"
                            },
                            {
                                label: "Doubly Linked List"
                            }
                        ]
                    },
                    {
                        label: "Trie"
                    },
                    {
                        label: "Array"
                    }
                ]
            },
            {
                label: "Algorithms",
                items: [
                    {
                        label: "Sorting"
                    },
                    {
                        label: "Searching"
                    }
                ]
            },
            {
                label: "Development",
  
                items: [
                    {
                        label: "Android"
                    },
                    {
                        label: "Web development"
                    }
                ]
            }
        ];
    }
}




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

Output:

 

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


Article Tags :