Angular PrimeNG SlideMenu Component - GeeksforGeeks

08 Sep, 2021
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 SlideMenu component in Angular PrimeNG. We will also learn about the properties, methods, styling along with their syntaxes that will be used in the code. 
SlideMenu component: It is used to display the menu list in the form of the sliding animation which helps to see the menu items in a stepwise manner.
Properties:
model: It is an array of menu items. It accepts the 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.
style: It is an inline style of the component. It accepts the string data type & the default value is null.
styleClass: It is the style class of the component. It accepts the string 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.
backLabel: It is the label of an element to navigate back. It accepts the string data type & the default value is back.
menuWidth: It is the width of the submenus. It accepts the number data type as input & the default value is 180.
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.
appendTo: It is the target element to attach the overlay, the valid values are “body” or a local ng-template variable of another element. It accepts any data type as input & the default value is null.
baseZIndex: It is the base zIndex value to use in layering. It accepts the number data type as input & 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.
showTransitionOptions: These are the 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: These are the transition options to hide the animation. It accepts the string data type & the default value is .1s linear.
Method:
toggle: It is used to toggle the visibility of the popup menu.
show: It is used to displays the popup menu.
hide: It is used to hides the popup menu.
 
Styling:
p-slidemenu: It is a container element.
p-slidemenu-wrapper: It is a wrapper of content.
p-slidemenu-content: It is a content element.
p-slidemenu-backward: It is an element to navigate to the previous menu on click.
p-menu-list: It is a list element.
p-menuitem: It is a menu item element.
p-menuitem-text: It is a label of a menu item.
p-menuitem-icon: It is an icon of a menu item.
p-submenu-icon: It is the arrow icon of a submenu.
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 the complete installation, it will look like the following:
 
Example 1: This is the basic example that shows how to use the SlideMenu component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG PanelMenu Component</h5><p-slideMenu [model]="gfg" ></p-slideMenu>
app.component.ts
import { Component } from '@angular/core';import { MenuItem } from 'primeng/api';  @Component({  selector: 'my-app',  templateUrl: './app.component.html'})export class AppComponent {  gfg: MenuItem[];    ngOnInit() {    this.gfg = [      {        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 { SlideMenuModule } from 'primeng/slidemenu';  @NgModule({  imports: [BrowserModule,               BrowserAnimationsModule,             SlideMenuModule],  declarations: [AppComponent],  bootstrap: [AppComponent]})export class AppModule {}
Output:
Example 2: In this example, we will make a slidemenu component using a popup.
app.component.html
<h5>PrimeNG SlideMenu Component</h5><button #btn type="button" pButton label="Click Here"        (click)="menu.toggle($event)"></button>  <p-slideMenu #menu [model]="gfg"     [popup]="true" [viewportHeight]="250"></p-slideMenu>
app.component.ts
import { Component } from '@angular/core';import { MenuItem } from 'primeng/api';  @Component({  selector: 'my-app',  templateUrl: './app.component.html'})export class AppComponent {  gfg: MenuItem[];    ngOnInit() {    this.gfg = [      {        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 { 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/showcase/#/slidemenu
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Top 10 Angular Libraries For Web Developers
How to use <mat-chip-list> and <mat-chip> in Angular Material ?
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Angular PrimeNG Dropdown Component
Angular 10 (blur) Event
Roadmap to Become a Web Developer in 2022
Installation of Node.js on Linux
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?