Open In App

Angular PrimeNG PanelMenu Component

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 PanelMenu component in Angular PrimeNG. We will also learn about the properties, styling along with their syntaxes that will be used in the code. 

PanelMenu component: It is used to make a menu in the form of a panel. It can be considered as a combination of accordion and tree components



Properties:

Styling:



 

Creating Angular application & module installation:

ng new appname
cd appname
npm install primeng --save
npm install primeicons --save

Project Structure: After complete installation, it will look like the following:

Example 1: This is the basic example that illustrates how to use the PanelMenu component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG PanelMenu Component</h5>
<p-panelMenu [model]="gfg"></p-panelMenu>




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
import { PanelMenuModule } from 'primeng/panelmenu';
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            PanelMenuModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}




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'
          }
        ]
      }
    ];
  }
}

 

Output:

Example 2: In this example, we will know how to use multiple property in the panelmenu component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG PanelMenu Component</h5>
<p-panelMenu [multiple]='false' [model]="gfg"></p-panelMenu>




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
  
import { AppComponent } from './app.component';
import { PanelMenuModule } from 'primeng/panelmenu';
  
@NgModule({
  imports: [BrowserModule, 
              BrowserAnimationsModule, 
            PanelMenuModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}




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'
          }
        ]
      }
    ];
  }
}

Output:

Reference: https://primeng.org/panelmenu


Article Tags :