Open In App

Angular PrimeNG ConfirmDialog Properties

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. In this article, we will learn how to use the ConfirmDialog Properties in Angular PrimeNG. 

The ConfirmDialog Component is used to make a dialog box containing confirm button to confirm the element.



Angular PrimeNG ConfirmDialog Properties:

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: Below is the example code that illustrates the use of Angular PrimeNG ConfirmDialog Properties.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG ConfirmDialog Position Property</h5>
  
<div class="p-grid p-dir-col">
    <div class="p-col">
        <p-button
            (click)="decidePos('left')"
            label="Get Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('right')"
            label="Get Right DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top')"
            label="Get Top DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom')"
            label="Get Bottom DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top-left')"
            label="Get Top-Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top-right')"
            label="Get Top-Right DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom-left')"
            label="Get Bottom-Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom-right')"
            label="Get Bottom-Right DialogBox"
            class="p-ml-3">
        </p-button>
    </div>
  
    <p-confirmDialog
        [style]="{ width: '60vw' }"
        key="dialogPos"
        [position]="pos">
    </p-confirmDialog>
  
    <p-messages
        [value]="ToastMessages">
    </p-messages>
</div>




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[];
    pos: string;
  
    constructor(private confirmationService: ConfirmationService) {}
  
    decidePos(pos: string) {
        this.pos = pos;
  
        this.confirmationService.confirm({
            message: "Do you want to buy this course ?",
            header: "GeeksforGeeks",
            icon: "pi pi-info-circle",
            accept: () => {
                this.ToastMessages = [
                    {
                        severity: "success",
                        summary: "Confirmed!",
                        detail: "You have bought this course."
                    }
                ];
            },
            reject: () => {
                this.ToastMessages = [
                    {
                        severity: "info",
                        summary: "Failure",
                        detail: "OOPs! Try buying course next time."
                    }
                ];
            },
            key: "dialogPos"
        });
    }
}




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 { MessagesModule } from "primeng/messages";
import { ConfirmDialogModule } from "primeng/confirmdialog";
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        ConfirmDialogModule,
        ButtonModule,
        MessagesModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent]
})
  
export class AppModule {}

Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG ConfirmDialog Properties using the transitionOptions property.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG ConfirmDialog Position Property</h5>
  
<div class="p-grid p-dir-col">
    <div class="p-col">
        <p-button
            (click)="decidePos('left')"
            label="Get Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('right')"
            label="Get Right DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top')"
            label="Get Top DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom')"
            label="Get Bottom DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top-left')"
            label="Get Top-Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('top-right')"
            label="Get Top-Right DialogBox"
            class="p-ml-3">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom-left')"
            label="Get Bottom-Left DialogBox">
        </p-button>
        <br><br>
        <p-button
            (click)="decidePos('bottom-right')"
            label="Get Bottom-Right DialogBox"
            class="p-ml-3">
        </p-button>
    </div>
  
    <p-confirmDialog
        [transitionOptions]="'0.8s'"
        [style]="{ width: '60vw' }"
        key="dialogPos"
        [position]="pos">
    </p-confirmDialog>
  
    <p-messages
        [value]="ToastMessages">
    </p-messages>
</div>




import { Component } from "@angular/core";
import { ConfirmationService } from "primeng/api";
import { Message } from "primeng/api";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
    styles: [],
    providers: [ConfirmationService]
})
export class AppComponent {
    ToastMessages: Message[];
    pos: string;
  
    constructor(private confirmationService: ConfirmationService) {}
  
    decidePos(pos: string) {
        this.pos = pos;
  
        this.confirmationService.confirm({
            message: "Do you want to buy this course ?",
            header: "GeeksforGeeks",
            icon: "pi pi-info-circle",
            accept: () => {
                this.ToastMessages = [
                    {
                        severity: "success",
                        summary: "Confirmed!",
                        detail: "You have bought this course."
                    }
                ];
            },
            reject: () => {
                this.ToastMessages = [
                    {
                        severity: "info",
                        summary: "Failure",
                        detail: "OOPs! Try buying course next time."
                    }
                ];
            },
            key: "dialogPos"
        });
    }
}

Output:

 

Reference: https://primefaces.org/primeng/confirmdialog


Article Tags :