Open In App

Angular PrimeNG Dialog Events

Last Updated : 24 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. In this article, we will know how to use the Dialog Events in Angular PrimeNG.

The Dialog Component is used to make a component containing some content to display in an overlay window.

Angular PrimeNG Dialog Events:

  • onShow: It is a callback that is called upon when dialogue is displayed.
  • onHide: It is a callback that is called upon when the dialog is hidden.
  • onResizeInit: It is a callback that is called upon when dialog resizing is initiated.
  • onResizeEnd: It is a callback that is called upon when dialog resizing is completed.
  • onDragEnd: It is a callback that is called upon when dialog dragging is completed.
  • onMaximize: It is a callback that is called upon when the dialog is maximized or unmaximized.

 

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:

 

Steps to run the application: Run the below command to see the output

ng serve --save

Example 1: This is the basic example that illustrates how to use the Angular PrimeNG Dialog Events using the onShow Event.

  • app.component.html:

HTML




<div style="text-align: center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h5>Angular PrimeNG Dialog Events</h5>
  
    <p-button
        (click)="Geek()"
        icon="pi pi-external-link"
        label="Click me Geeks">
    </p-button>
  
    <p-dialog
        (onShow)="onShow()"
        header="GeeksforGeeks"
        [(visible)]="geek"
        [style]="{ width: '20vw' }">
        <p>
            GeeksforGeeks is an Computer 
            Science Portal for all the geeks.
        </p>
    </p-dialog>
</div>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent { 
    geek: boolean;
  
    Geek() {
        this.geek = true;
    }
  
    onShow(){
        alert("Hi I'm Opened");
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent }   from './app.component';
import { DialogModule } from 'primeng/dialog';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserAnimationsModule,
        DialogModule,
        ButtonModule
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Example 2: This is another basic example that illustrates how to use the Angular PrimeNG Dialog Events using the onHide Event.

  • app.component.html:

HTML




<div style="text-align: center">
    <h1 style="color: green">GeeksforGeeks</h1>
    <h5>Angular PrimeNG Dialog Events</h5>
  
    <p-button
        (click)="Geek()"
        icon="pi pi-external-link"
        label="Click me Geeks">
    </p-button>
  
    <p-dialog
        (onHide)="onHide()"
        header="GeeksforGeeks"
        [(visible)]="geek"
        [style]="{ width: '20vw' }">
        <p>
            GeeksforGeeks is an Computer 
            Science Portal for all the geeks.
        </p>
    </p-dialog>
</div>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent { 
    geek: boolean;
  
    Geek() {
        this.geek = true;
    }
  
    onHide(){
        alert("Hi I'm Closed");
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent }   from './app.component';
import { DialogModule } from 'primeng/dialog';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserAnimationsModule,
        DialogModule,
        ButtonModule
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

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



Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads