Open In App

Angular PrimeNG OverlayPanel Properties

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. It provides a lot of templates, components, theme design, an extensive icon library, and much more. In this article, we will see the Angular PrimeNG Dynamic OverlayPanel Properties.

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. The properties allow us to customize the component easily which extends the functionality of the component. There are various Angular PrimeNG Dynamic OverlayPanel Properties are described below:

Angular PrimeNG Dynamic OverlayPanel Properties:

  • dismissible(boolean): It enables hiding the overlay when the outside is clicked. The default value is true.
  • showCloseIcon(boolean): If enabled, it displays a close icon at the top right corner. The default value is false.
  • ariaCloseLabel(string): It is the aria-label of the close icon. The default value is close.
  • style(string): It is the inline style of the component.
  • styleClass(string): It is the style class of the component.
  • appendTo(any): The target element to attach the panel.
  • baseZIndex(number): It is the base zIndex value to use in layering. The default value is 0.
  • autoZIndex(boolean): It sets whether to automatically manage to layer. The default value is true.
  • showTransitionOptions(string): It sets the transition options of the show animation. The default value is  .12s cubic-bezier(0, 0, 0.2, 1).
  • hideTransitionOptions(string):  It sets the transition options of the hide animation. The default value is .1s linear.
  • focusOnShow(boolean): If enabled, the first button receives focus on the show. The default value is true.

Syntax:

<p-overlayPanel #op
      [dismissible]="..."
      [style]="{ ... }">
    <ng-template pTemplate>
        ...    
    </ng-template>
</p-overlayPanel>

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new geeks_angular

Step 2:  After creating your project folder i.e. geeks_angular, move to it using the following command.

cd geeks_angular

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: The project structure will look like the following:

 

Steps to run the application: Write the below command to run the application:

ng serve --open

Example 1: In the following example, we have the dismissible set to false and showCloseIcon set to true. 

  • app.component.html:

HTML




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Dynamic OverlayPanel Properties</h3>
<br /><br />
<p-button
    [label]="'Overlay Panel'"
    icon="pi pi-search"
    (click)="op1.toggle($event)">
</p-button>
 
<p-overlayPanel
    #op1
    [dismissible]="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: In the following example, we have set showCloseIcon to false.

  • app.component.html:

HTML




<h1 style="color: green; text-align: center;">
    GeeksforGeeks
</h1>
<h3>Angular PrimeNG Dynamic OverlayPanel Properties</h3>
<br /><br />
<p-button
    [label]="'Overlay Panel'"
    icon="pi pi-search"
    (click)="op1.toggle($event)">
</p-button>
 
<p-overlayPanel
    #op1
    [dismissible]="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 : 08 Feb, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads