Angular PrimeNG ConfirmDialog Component - GeeksforGeeks

19 Oct, 2021
Angular PrimeNG is a framework used with angular to create components with great styling and this framework is very easy to use and is used to make responsive websites.
In this article, we will know how to use ConfirmDialog component in angular primeNG. The ConfirmDialog component is used to make a dialog box containing confirm button to confirm the element.
Properties:
message: It is the message of the confirmation. It is of string data type, the default value is null.
key: It is the Optional key to match the key of the confirm dialog. It is of string data type, the default value is null.
icon: It is the Icon to display next to the message. It is of string data type, the default value is null.
header: It is the Header text of the dialog. It is of string data type, the default value is null.
accept: It is the Callback to execute when action is confirmed.
reject: It is the Callback to execute when action is rejected
acceptLabel: It is the Label of the accept button. It is of string data type, the default value is null.
rejectLabel: It is the Label of the reject button. It is of string data type, the default value is null.
acceptIcon: It is the Icon of the accept button. It is of string data type, the default value is null.
rejectIcon: It is the Icon of the reject button. It is of string data type, the default value is null.
acceptButtonStyleClass: It is used to set the Style class of the accept button. It is of string data type, the default value is null.
rejectButtonStyleClass: It is used to set the Style class of the reject button. It is of string data type, the default value is null.
acceptVisible: It is used to set the Visibility of the accept button. It is of boolean datatype & the default value is false.
rejectVisible: It is used to set the Visibility of the reject button. It is of boolean datatype & the default value is false.
style: It is the Inline style of the component. It is of object data type, the default value is null.
styleClass: It is the Style class of the component. It is of string data type, the default value is null.
maskStyleClass: It is the Style class of the mask. It is of string data type, the default value is null.
blockScroll: It is used to specify Whether background scroll should be blocked when the dialog is visible. It is of boolean datatype & the default value is false.
closeOnEscape: It Specifies if pressing the escape key should hide the dialog. It is of boolean datatype & the default value is false.
dismissableMask: It Specifices if clicking the modal background should hide the dialog. It is of boolean datatype & the default value is false.
defaultFocus: It is the Element to receive the focus when the dialog gets visible.
Events:
onHide: It is the callback that is fired when dialog is hidden.
 
Creating Angular Application And Installing Module:
Step 1: Create a 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: This is the basic example which shows how to use ConfirmDialog component 
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG ConfirmDialog Component</h5><p-confirmDialog [style]="{width: '60vw'}"></p-confirmDialog><p-button (click)="GetConfirm()" label="Click Here"></p-button>
app.module.ts
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 { ConfirmDialogModule } from 'primeng/confirmdialog';  @NgModule({  imports: [    BrowserModule,    BrowserAnimationsModule,    ConfirmDialogModule,    ButtonModule,  ],  declarations: [ AppComponent ],  bootstrap:    [ AppComponent ]})  export class AppModule { }
app.component.ts
import { Component } from '@angular/core';import {ConfirmationService} from 'primeng/api';import { PrimeNGConfig } from 'primeng/api';  @Component({  selector: 'app-root',  templateUrl: './app.component.html',  styles: [],  providers: [ConfirmationService]})export class AppComponent {         constructor(private confirmationService: ConfirmationService,    private primengConfig: PrimeNGConfig) {}      GetConfirm() {        this.confirmationService.confirm({            message: 'Angular PrimeNG ConfirmDialog Component',            header: 'GeeksforGeeks',        });    }}
Output:
Reference: https://primefaces.org/primeng/showcase/#/confirmdialog
varshagumber28
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Top 10 Angular Libraries For Web Developers
Angular 10 (blur) Event
Angular PrimeNG Dropdown Component
How to make a Bootstrap Modal Popup in Angular 9/8 ?
How to create module with Routing in Angular 9 ?
Roadmap to Become a Web Developer in 2022
Top 10 Projects For Beginners To Practice HTML and CSS Skills
How to fetch data from an API in ReactJS ?
Installation of Node.js on Linux
Convert a string to an integer in JavaScript