Open In App

Angular PrimeNG Panel Advanced

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. This article will show us how to use the Panel Advanced in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The Panel Component allows us to make an element containing a header and some content associated with that header.

Syntax:

<p-panel header="..." [toggleable] = "true" >
    <ng-template pTemplate="icons">
        <button
            pButton
            class="p-panel-header-icon p-link"
            icon="..."
      (click)="menu.toggle($event)"
    </button>
    >

    <p-menu #menu [model] = "gfg"[popup] = "true" ></p - menu >
  </ng - template >
    <p>....</p>
</p - panel >

 

Angular PrimeNG Panel Advanced Properties:

  • header: It is the header text of the panel. It is of string data type, the default value is null.
  • toggleable: It defines whether the content of the panel can be expanded and collapsed or not. It is of Boolean data type, the default value is false.

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:

ng serve --open

Example 1: Below is the basic example demonstrating the use of Angular PrimeNG Panel Advanced.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Panel Advanced</h5>
  
<p-panel header="GeeksforGeeks" 
    [toggleable]="true">
    <ng-template pTemplate="icons">
        <button pButton class="p-panel-header-icon 
            p-link" icon="pi pi-code" 
                (click)="menu.toggle($event)">
          </button>
        
        <p-menu #menu [model]="gfg" [popup]="true"></p-menu>
    </ng-template>
    <p>
        Angular PrimeNG is a framework used with angular to create 
          components with great styling and this framework is very 
          easy to use and is used to make responsive websites.
    </p>
</p-panel>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import {MessageService} from 'primeng/api';
import {MenuItem} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [MessageService]
})
  
export class AppComponent { 
    gfg: MenuItem[];
  
    constructor(private messageService: MessageService) {}
  
    ngOnInit() {
        this.gfg = [
            {
                label: 'Languages',
                items: [
                {
                    label: 'C++'
                },
                {
                    label: 'Java'
                },
                {
                    label: 'Python'
                },
                {
                    label: 'C#'
                }
            ]},
        ];
    }
}


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


Output:

 

Example 2: Below is another example demonstrating the use of Angular PrimeNG Panel Advanced using an image.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Panel Advanced</h5>
  
<p-panel header="GeeksforGeeks" 
         [toggleable]="true">
    <ng-template pTemplate="icons">
        <button pButton class="p-panel-header-icon p-link" 
            icon="pi pi-code" 
                (click)="menu.toggle($event)">
        </button>
  
        <p-menu #menu [model]="gfg" 
                [popup]="true"></p-menu>
    </ng-template>
    <p>
        <img alt="gfg" height="200px" src=
  
        <img alt="gfg" height="200px" src=
  
        <img alt="gfg" height="200px" src=
    </p>
</p-panel>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import {MessageService} from 'primeng/api';
import {MenuItem} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    providers: [MessageService]
})
  
export class AppComponent { 
    gfg: MenuItem[];
      
    constructor(private messageService: MessageService) {}
      
    ngOnInit() {
        this.gfg = [
            {
                label: 'Courses',
                items: [
                {
                    label: 'DSA'
                },
                {
                    label: 'Test Series'
                },
                {
                    label: 'System Design'
                }
            ]},
        ];
    }
}


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


Output:

 

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



Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads