Open In App

Angular PrimeNG OverlayPanel Dismissable and CloseIcon

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 Dynamic OverlayPanel Dismissable and CloseIcon in Angular PrimeNG.

OverlayPanel is a container component positioned as connected to its target. It appears normally when a button is clicked as a pop-up with some action to take as selecting an item and then closing it. It is said to be dynamic because it does not appear on the first mount but appears on interaction with the website.

OverlayPanel Dismissible and CloseIcon: If dismissible is set to true, clicking outside the panel closes it. If showCloseIcon is set to true, it displays a close icon at the top right corner to close the panel.

 

Angular PrimeNG Dynamic OverlayPanel Dismissable and CloseIcon:

  • dismissable: It is used to enable the hiding of the overlay panel when it is clicked outside. It is of boolean type and the default value is true.
  • showCloseIcon: It is used to display a close icon at the top right corner of the overlay panel.

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 --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Dynamic OverlayPanel Dismissable and CloseIcon using dismissable=”false” and closeIcon=”true”. 

  • app.component.html:

HTML




<h1 style="color: green;">GeeksforGeeks</h1>
<h3>
    Angular PrimeNG Dynamic OverlayPanel Dismissable and CloseIcon
</h3>
  
<p-button
    [label]="'Overlay Panel'"
    icon="pi pi-search"
    (click)="gfg.toggle($event)">
</p-button>
  
<p-overlayPanel
    #gfg
    [dismissable]="false"
    [showCloseIcon]="true"
    [style]="{ width: '450px' }">
    <p-table
        #dt
        [columns]="cols"
        [value]="tutorials"
        [paginator]="true"
        [rows]="3"
        responsiveLayout="scroll">
        <ng-template pTemplate="body" 
             let-rowData let-columns="columns">
            <tr [pSelectableRow]="rowData">
                <td *ngFor="let col of columns">
                    {{ rowData[col.field] }}
                </td>
            </tr>
        </ng-template>
    </p-table>
</p-overlayPanel>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { OverlayPanel } from "primeng/overlaypanel";
import { MessageService } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html"
})
  
export class AppComponent {
    constructor(private messageService: MessageService) {}
    tutorials: Tutorial[];
    cols: any[];
    ngOnInit() {
        this.tutorials = [
            {
                title: "Queue",
                category: "Data Structure",
                rating: 8
            },
            {
                title: "Circularly LinkedList",
                category: "Data Structure",
                rating: 1
            },
            {
                title: "Doubly LinkedList",
                category: "Data Structure",
                rating: 3
            },
            {
                title: "Singly LinkedList",
                category: "Data Structure",
                rating: 5
            },
            {
                title: "Doubly Ended Queue",
                category: "Data Structure",
                rating: 10
            },
            {
                title: "Binary Search Tree",
                category: "Data Structure",
                rating: 2
            },
            {
                title: "Red Black Tree",
                category: "Data Structure",
                rating: 9
            },
            {
                title: "Breadth First Search",
                category: "Graph",
                rating: 6
            },
            {
                title: "Floyd's Cycle",
                category: "Algorithm",
                rating: 7
            },
            {
                title: "Travelling Salesman Problem",
                category: "Algorithm",
                rating: 4
            },
            {
                title: "Bellman Ford",
                category: "Graph",
                rating: 8
            },
            {
                title: "KMP Algorithm",
                category: "String",
                rating: 10
            }
        ];
        this.cols = [
            { field: "title", header: "Title" },
            { field: "category", header: "Category" },
            { field: "rating", header: "Rating" }
        ];
    }
}
  
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}


  • 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 { ButtonModule } from "primeng/button";
import { OverlayPanelModule } from "primeng/overlaypanel";
import { MessageService } from "primeng/api";
import { TableModule } from "primeng/table";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OverlayPanelModule,
        ButtonModule,
        TableModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [MessageService]
})
  
export class AppModule {}


Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG Dynamic OverlayPanel Dismissable and CloseIcon using dismissable=”true” and closeIcon=”false”.

  • app.component.html:

HTML




<h1 style="color: green;">GeeksforGeeks</h1>
<h3>
    Angular PrimeNG Dynamic OverlayPanel Dismissable and CloseIcon
</h3>
  
<p-button
    [label]="'Overlay Panel'"
    icon="pi pi-search"
    (click)="gfg.toggle($event)">
</p-button>
  
<p-overlayPanel
    #gfg
    [dismissable]="true"
    [showCloseIcon]="false"
    [style]="{ width: '450px' }">
    <p-table
        #dt
        [columns]="cols"
        [value]="tutorials"
        [paginator]="true"
        [rows]="3"
        responsiveLayout="scroll">
        <ng-template pTemplate="body" 
             let-rowData let-columns="columns">
            <tr [pSelectableRow]="rowData">
                <td *ngFor="let col of columns">
                    {{ rowData[col.field] }}
                </td>
            </tr>
        </ng-template>
    </p-table>
</p-overlayPanel>


  • app.component.ts:

Javascript




import { Component } from "@angular/core";
import { OverlayPanel } from "primeng/overlaypanel";
import { MessageService } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html"
})
  
export class AppComponent {
    constructor(private messageService: MessageService) {}
    tutorials: Tutorial[];
    cols: any[];
    ngOnInit() {
        this.tutorials = [
            {
                title: "Queue",
                category: "Data Structure",
                rating: 8
            },
            {
                title: "Circularly LinkedList",
                category: "Data Structure",
                rating: 1
            },
            {
                title: "Doubly LinkedList",
                category: "Data Structure",
                rating: 3
            },
            {
                title: "Singly LinkedList",
                category: "Data Structure",
                rating: 5
            },
            {
                title: "Doubly Ended Queue",
                category: "Data Structure",
                rating: 10
            },
            {
                title: "Binary Search Tree",
                category: "Data Structure",
                rating: 2
            },
            {
                title: "Red Black Tree",
                category: "Data Structure",
                rating: 9
            },
            {
                title: "Breadth First Search",
                category: "Graph",
                rating: 6
            },
            {
                title: "Floyd's Cycle",
                category: "Algorithm",
                rating: 7
            },
            {
                title: "Travelling Salesman Problem",
                category: "Algorithm",
                rating: 4
            },
            {
                title: "Bellman Ford",
                category: "Graph",
                rating: 8
            },
            {
                title: "KMP Algorithm",
                category: "String",
                rating: 10
            }
        ];
        this.cols = [
            { field: "title", header: "Title" },
            { field: "category", header: "Category" },
            { field: "rating", header: "Rating" }
        ];
    }
}
  
export interface Tutorial {
    title?: string;
    category?: string;
    rating?: number;
}


  • 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 { ButtonModule } from "primeng/button";
import { OverlayPanelModule } from "primeng/overlaypanel";
import { MessageService } from "primeng/api";
import { TableModule } from "primeng/table";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OverlayPanelModule,
        ButtonModule,
        TableModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [MessageService]
})
  
export class AppModule {}


Output:

 

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



Last Updated : 31 Jan, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads