Open In App

Angular PrimeNG Dialog Events

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:

 



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.




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




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");
    }
}




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.




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




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");
    }
}




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


Article Tags :