Angular PrimeNG Dialog Templates
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 Dialog Templates in Angular PrimeNG.
The Dialog Component is used to make a component containing some content to display in an overlay window.
This article will show the Dialog Templating in Angular PrimeNG. The templates are used to put some content on some pre-structured containers.
Angular PrimeNG Dialog Templates:
- header: It is used to define the header of the dialog.
- footer: It is used to define the footer of the dialog.
- content: It is used to define the content of the dialog.
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 Dialog Templates using the header and the content templates.
- app.component.html:
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Dialog Templates.</ h5 > < p-button (click)="Geeks()" icon = "pi pi-code" label = "Show" > </ p-button > < p-dialog [(visible)]="geeks" [style]="{ width: '40vw' }"> < ng-template pTemplate = "header" > < h2 >GeeksforGeeks</ h2 > </ ng-template > < ng-template pTemplate = "content" > < p > 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. </ p > </ ng-template > </ p-dialog > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent { geeks: boolean; Geeks() { this .geeks = true ; } } |
- 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 { DialogModule } from 'primeng/dialog' ; import { ButtonModule } from 'primeng/button' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, DialogModule, ButtonModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Example 2: Below is another example code that illustrates the use of Angular PrimeNG Dialog Templates using the content and the footer templates.
- app.component.html:
HTML
< h1 style = "color: green;" >GeeksforGeeks</ h1 > < h5 >Angular PrimeNG Dialog Templates.</ h5 > < p-button (click)="Geeks()" icon = "pi pi-code" label = "Show Geek" > </ p-button > < p-dialog [(visible)]="geeks" [style]="{ width: '40vw' }"> < ng-template pTemplate = "content" > < p > 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. </ p > </ ng-template > < ng-template pTemplate = "footer" > < p-button icon = "pi pi-check" (click)=" geeks = false " label = "Accept" styleClass = "p-button-success" > </ p-button > < p-button icon = "pi pi-times" (click)=" geeks = false " label = "Reject" styleClass = "p-button-danger" > </ p-button > </ ng-template > </ p-dialog > |
- app.component.ts:
Javascript
import { Component } from '@angular/core' ; @Component({ selector: 'app-root' , templateUrl: './app.component.html' , }) export class AppComponent { geeks: boolean; Geeks() { this .geeks = true ; } } |
- 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 { DialogModule } from 'primeng/dialog' ; import { ButtonModule } from 'primeng/button' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, DialogModule, ButtonModule ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:

Reference: https://primefaces.org/primeng/dialog
Please Login to comment...