Open In App

Angular PrimeNG ConfirmDialog Component

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:

Events:



 

Creating Angular Application And Installing Module:

ng new appname
cd appname
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 




<h2>GeeksforGeeks</h2>
<h5>PrimeNG ConfirmDialog Component</h5>
<p-confirmDialog [style]="{width: '60vw'}"></p-confirmDialog>
<p-button (click)="GetConfirm()" label="Click Here"></p-button>




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 { }




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://primeng.org/confirmdialog


Article Tags :