Open In App

Angular PrimeNG Dynamic OverlayPanel Styling

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 see Angular PrimeNG Dynamic OverlayPanel Styling.

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. Styling is used to override some default styles to match the theme of the site that we are working on. 

Angular PrimeNG Dynamic OverlayPanel Styling:

  • p-overlaypanel: This is used for the Container element.
  • p-overlaypanel-content: This is used for the Content of the panel.
  • p-overlaypanel-close: This is used for the  Close icon.

Syntax:

<p-overlayPanel #op [showCloseIcon]="true"
                    [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 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:

 

Example 1: This example describes the basic usage of Dynamic OverlayPanel Styling in Angular PrimeNG by implementing the p-overlaypanel .

  • app.component.html

HTML




<div style="width:80%">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG Dynamic OverlayPanel Styling
    </h2>
    <p-button [label]="'Open Panel'" 
              icon="pi pi-search" 
              (click)="op.toggle($event)">
    </p-button>
  
    <p-overlayPanel #op [showCloseIcon]="true" 
                        [style]="{background:'green',
                                  color:'white'}">
        <ng-template pTemplate>
            Welcome to GeeksforGeeks
        </ng-template>
    </p-overlayPanel>
</div>


  • 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) { }
    ngOnInit() { }
}


  • 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';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OverlayPanelModule,
        ButtonModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [MessageService],
})
export class AppModule { }


Output:

 

Example 2: In this example, we will style the overlaypanel with red background and 2% padding.

  • app.component.html

HTML




<div style="width:80%">
    <h1 style="color: green;">
        GeeksforGeeks
    </h1>
    <h2>
        Angular PrimeNG Dynamic OverlayPanel Styling
    </h2>
    <p-button [label]="'Overlay Panel'" 
              icon="pi pi-search" 
              (click)="op1.toggle($event)">
    </p-button>
  
    <p-overlayPanel #op1 [showCloseIcon]="true" 
                         [style]="{ background: 'red',
                                    padding:'2%' }">
        <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>
</div>


  • app.component.ts

Javascript




import { Component } from '@angular/core';
import { OverlayPanel } from 'primeng/overlaypanel';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styleUrls: ['./app.component.css']
})
export class AppComponent {
    constructor() { }
    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,
            },
  
        ];
        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 { TableModule } from 'primeng/table';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        OverlayPanelModule,
        ButtonModule,
        TableModule,
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }


Output:

 

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



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