Open In App

Angular PrimeNG Slide Menu Effects

Last Updated : 19 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 know how to use the Slide Menu Effects in Angular PrimeNG. We will also learn about the properties, events, methods & styling along with their syntaxes that will be used in the code.

The Menu component is used to make a component that contains some information & supports either static or dynamic positioning.

Syntax:

<p-slideMenu
      #menu
      [model]="..."
      effectDuration="..."
      [viewportHeight]="..."
      easing="..."
>
</p-slideMenu>

 

Angular PrimeNG Slide Menu Effects properties:

  • model: It is an array of menu items. It accepts the array data type & the default value is null.
  • easing: It is the animation to use for sliding. It accepts the string data type & the default value is ease-out.
  • effectDuration: It is the duration of the sliding animation in milliseconds. It accepts any data type as input & the default value is 250.
  • viewportHeight: It is the height of the scrollable area, a scrollbar appears if a menu height is longer than this value. It accepts the number data type as input & the default value is 175.

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: It will look like the following:

 

Steps to run the application: Run the below command to see the output.

ng serve --open

Example 1: Below is the example code that illustrates the use of the Angular PrimeNG Slide Menu Effects using the easing=”ease-in-out”

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG SlideMenu Effects</h5>
  
<p-slideMenu
    #menu
    [model]="gfg"
    effectDuration="1200"
    [viewportHeight]="200"
    easing="ease-in">
</p-slideMenu>


  • 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:'Courses',
               items:[
                  {
                     label:'For Freshers',
                     items:[
                        {
                           label:'DSA Self Paced',
                        },
                        {
                           label:'C++ STL',
                        },
  
                     ]
                  }
               ]
            },
        ];
    }    
}


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


Output:

 

Example 2: Below is another example code that illustrates the use of the Angular PrimeNG Slide Menu Effects using the easing=”ease-in-out”

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG SlideMenu Effects</h5>
  
<p-slideMenu
    #menu
    [model]="gfg"
    effectDuration="1100"
    [viewportHeight]="200"
    easing="ease-in-out">
</p-slideMenu>


  • 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:'Tutorials',
               items:[
                  {
                     label:'React',
                     items:[
                        {
                           label:'React Ant Design',
                        },
                        {
                           label:'React Blueprint UI',
                        },
  
                     ]
                  }
               ]
            },
        ];
    }    
}


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


Output:

 

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



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

Similar Reads