Angular PrimeNG ConfirmDialog Animation Configuration
Angular PrimeNG is a framework used with angular to create components with great styling this framework is very easy to use and is used to make responsive websites. This article will show us how to use the ConfirmDialog Basic in Angular PrimeNG.
The ConfirmDialog component is used to make a dialog box containing confirm button to confirm the element.
Angular PrimeNG ConfirmPopup Animation Configuration properties:
- transitionOptions: It is used to set the transition options of the show and hide animation.
Syntax:
<p-confirmDialog [transitionOptions]="'...'"> </p-confirmDialog>
Creating Angular Application And Installing Module:
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: In the below code, we will make use of the above syntax to demonstrate the use of the ConfirmDialog Animation Configuration.
- app.component.html:
HTML
< div style = "text-align:center" > < h2 style = "color: green" >GeeksforGeeks</ h2 > < h5 >Angular PrimeNG ConfirmDialog Animation Configuration</ h5 > < p-confirmDialog [style]="{ width: '30vw' }" [transitionOptions]="'3000ms'"> </ p-confirmDialog > < p-button (click)="decision()" label = "Buy GfG Course" > </ p-button > < p-messages [value]="ToastMessages"> </ p-messages > </ div > |
- app.component.ts:
Javascript
import { Component } from "@angular/core" ; import { ConfirmationService } from "primeng/api" ; import { Message } from "primeng/api" ; import { PrimeNGConfig } from "primeng/api" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" , styles: [], providers: [ConfirmationService] }) export class AppComponent { ToastMessages: Message[]; constructor( private confirmationService: ConfirmationService, private primengConfig: PrimeNGConfig ) {} decision() { this .confirmationService.confirm({ message: "Confirm Buying this course?" , header: "GeeksforGeeks" , icon: "pi pi-exclamation-triangle" , accept: () => { this .ToastMessages = [ { severity: "success" , summary: "Success" , detail: "You have bought this course!" } ]; }, reject: () => { this .ToastMessages = [ { severity: "info" , summary: "Rejected" , detail: "You have rejected bought this course!" } ]; } }); } } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import {RouterModule} from '@angular/router' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import { ButtonModule } from 'primeng/button' ; import { MessagesModule } from 'primeng/messages' ; import { ConfirmDialogModule } from 'primeng/confirmdialog' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, ConfirmDialogModule, ButtonModule, MessagesModule, ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:
.gif)
Example 2: In the below code, we will make use of the above syntax to demonstrate the use of the ConfirmDialog Animation Configuration.
- app.component.html:
HTML
< div style = "text-align:center" > < h2 style = "color: green" >GeeksforGeeks</ h2 > < h5 >Angular PrimeNG ConfirmDialog Animation Configuration</ h5 > < p-confirmDialog [style]="{ width: '30vw' }"> </ p-confirmDialog > < p-button (click)="decision()" label = "Buy GfG Course" > </ p-button > < p-messages [value]="ToastMessages"> </ p-messages > </ div > |
- app.component.html:
Javascript
import { Component } from "@angular/core" ; import { ConfirmationService } from "primeng/api" ; import { Message } from "primeng/api" ; import { PrimeNGConfig } from "primeng/api" ; @Component({ selector: "app-root" , templateUrl: "./app.component.html" , styles: [], providers: [ConfirmationService] }) export class AppComponent { ToastMessages: Message[]; constructor( private confirmationService: ConfirmationService, private primengConfig: PrimeNGConfig ) {} decision() { this .confirmationService.confirm({ message: "Confirm Buying this course?" , header: "GeeksforGeeks" , icon: "pi pi-exclamation-triangle" , accept: () => { this .ToastMessages = [ { severity: "success" , summary: "Success" , detail: "You have bought this course!" } ]; }, reject: () => { this .ToastMessages = [ { severity: "info" , summary: "Rejected" , detail: "You have rejected bought this course!" } ]; } }); } } |
- app.module.ts:
Javascript
import { NgModule } from '@angular/core' ; import { BrowserModule } from '@angular/platform-browser' ; import {RouterModule} from '@angular/router' ; import { BrowserAnimationsModule } from '@angular/platform-browser/animations' ; import { AppComponent } from './app.component' ; import { ButtonModule } from 'primeng/button' ; import { MessagesModule } from 'primeng/messages' ; import { ConfirmDialogModule } from 'primeng/confirmdialog' ; @NgModule({ imports: [ BrowserModule, BrowserAnimationsModule, ConfirmDialogModule, ButtonModule, MessagesModule, ], declarations: [ AppComponent ], bootstrap: [ AppComponent ] }) export class AppModule { } |
Output:
.gif)
Reference: https://primefaces.org/primeng/confirmdialog
Please Login to comment...