Open In App

Angular PrimeNG Slide Menu Popup

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 Popup in Angular PrimeNG.

SlideMenu component 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. By default, the SlideMenu is inline, but popup mode maybe is used by activating the popup property and invoking the toggle function with the event passed in from the anchor element.



Angular PrimeNG Slide Menu Popup Properties:

Syntax:



<button
    #btn
    type="button"
    pButton
    label="..."
    (click)="...">
</button>

<p-slideMenu #menu 
    [model]="gfg" 
    [popup]="true"
    [viewportHeight]="...">
</p-slideMenu>

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: 

 

ng serve --open

Example 1: Below is the example code that illustrates the use of the Angular PrimeNG SlideMenu popup.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>PrimeNG SlideMenu Popup</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>




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: "HTML",
        items: [
          {
            label: "HTML 1",
          },
          {
            label: "HTML 2",
          },
        ],
      },
      {
        label: "Angular",
  
        items: [
          {
            label: "Angular 1",
          },
          {
            label: "Angular 2",
          },
        ],
      },
    ];
  }
}




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 Angular PrimeNG SlideMenu popup using some different item values.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>PrimeNG SlideMenu Popup</h5>
<button #btn type="button" pButton
             label="Click Here" 
             class="p-button-success" 
             icon="pi pi-check"
             (click)="menu.toggle($event)">
</button>
  
<p-slideMenu #menu [model]="gfg" 
                   [popup]="true" 
                   [viewportHeight]="180">
</p-slideMenu>




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: "Data Structure",
        items: [
          {
            label: "Linked List",
          },
          {
            label: "Stacks",
          },
        ],
      },
      {
        label: "Algorithms",
  
        items: [
          {
            label: "Breadth First Search (BFS) Algorithm.",
          },
          {
            label: "Depth First Search (DFS) Algorithm.",
          },
        ],
      },
    ];
  }
}




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


Article Tags :