Open In App

Angular PrimeNG ConfirmDialog Responsive

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 Responsive in Angular PrimeNG. 

The ConfirmDialog component is used to make a dialog box containing confirm button to confirm the element. ConfirmDialog’s width may be modified using the breakpoints parameter according to screen size. Breakpoints should have an object literal as their value, with keys representing the largest screen sizes and values representing the widths of each screen.



Syntax:

<p-confirmDialog 
    [breakpoints]="{.....}" 
    [style]="{width:'...'}">
</p-confirmDialog>

Angular PrimeNG ConfirmDialog Responsive Properties:



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: To run the above file run the below command:

ng serve --save

Example 1: Below is the example that illustrates the use of Angular PrimeNG ConfirmDialog Responsive.

app.component.html:




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG ConfirmDialog Responsive Component</h5>
  
<p-confirmDialog 
    [breakpoints]="{'960px': '75vw', '640px': '100vw'}" 
    [style]="{width: '60vw'}">
</p-confirmDialog>
  
<p-button 
    (click)="GetConfirm()" 
    label="Click Here">
</p-button>
<p-messages [value]="myMsgs"></p-messages>

app.component.ts:




import { Component } from '@angular/core';
import {ConfirmationService} from 'primeng/api';
import { PrimeNGConfig } from 'primeng/api';
import {Message} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styles: [],
    providers: [ConfirmationService]
})
  
export class AppComponent {
  
    myMsgs: Message[] = []; 
    constructor(private confirmationService: ConfirmationService,
    private primengConfig: PrimeNGConfig) {}
  
    GetConfirm() {
        this.confirmationService.confirm({
            message: 'Angular PrimeNG ConfirmDialog Component',
            header: 'GeeksforGeeks',
            accept: () => {
                this.myMsgs = [
                  {
                      severity:'success'
                    summary:'Success'
                    detail:'Geek has confirmed'
                  }
                ];
            },
            reject: () => {
                this.myMsgs = [
                    {
                      severity:'error'
                      summary:'Failure'
                      detail:'Geek has rejected'
                     }
                ];
            }
        });
    }
}

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 { 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 that illustrates the use of Angular PrimeNG ConfirmDialog Responsive.

app.component.html:




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG ConfirmDialog Responsive Component</h5>
  
<p-confirmDialog 
    [breakpoints]="{
        '1000px': '50vw', 
        '800px': '80vw', 
        '700px': '100vw'
    }" [style]="{width: '60vw'}">
</p-confirmDialog>
  
<p-button 
    (click)="GetConfirm()" 
    label="Click Here">
</p-button>
<p-messages [value]="myMsgs"></p-messages>

app.component.ts:




import { Component } from '@angular/core';
import {ConfirmationService} from 'primeng/api';
import { PrimeNGConfig } from 'primeng/api';
import {Message} from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styles: [],
    providers: [ConfirmationService]
})
  
export class AppComponent {
  
    myMsgs: Message[] = []; 
    constructor(private confirmationService: ConfirmationService,
    private primengConfig: PrimeNGConfig) {}
  
    GetConfirm() {
        this.confirmationService.confirm({
            message: 'Angular PrimeNG ConfirmDialog Component',
            header: 'GeeksforGeeks',
            accept: () => {
                this.myMsgs = [
                  {
                      severity:'success'
                    summary:'Success'
                    detail:'Geek has confirmed'
                  }
                ];
            },
            reject: () => {
                this.myMsgs = [
                    {
                      severity:'error'
                      summary:'Failure'
                      detail:'Geek has rejected'
                     }
                ];
            }
        });
    }
}

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

Output:

 

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


Article Tags :