Open In App

Angular PrimeNG Dialog Properties

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 learn how to use the Dialog Properties in Angular PrimeNG.  

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



Angular PrimeNG Dialog 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:

 

To run the above file run the below command:

ng serve --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG Dialog Properties using the draggable, and resizable properties.




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Dialog Properties</h5>
  
<p-button 
    (click)="GFG()" 
    icon="pi pi-check" 
    label="Click here Geek!">
</p-button>
  
<p-dialog header="GeeksforGeeks" 
    [(visible)]="gfg" [modal]="true"
    [draggable]="true" [resizable]="true"
    [style]="{width: '75vw'}" 
    [baseZIndex]="10000">
    <p>
        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. 
    </p>
    <ng-template pTemplate="footer">
        <p-button icon="pi pi-check" 
            (click)="gfg=false
            label="Confirm" 
            styleClass="p-button-text">
        </p-button>
  
        <p-button icon="pi pi-times" 
            (click)="gfg=false
            label="Reject">
        </p-button>
    </ng-template>
</p-dialog>




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent { 
    constructor(private primengConfig: PrimeNGConfig) {}
    gfg: boolean;
      
    ngOnInit() {
        this.primengConfig.ripple = true;
    }
    GFG() {
        this.gfg = true;
    }
}




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

Output:

 

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




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG Dialog Position Properties</h5>
  
<p-button (click)="GFG()" 
    label="Click Here Geek!">
</p-button>
  
<p-dialog position="top"
    header="GeeksforGeeks" [(visible)]="gfg">
    <p>I am Top!</p>
</p-dialog>
  
<p-dialog position="bottom"
    header="GeeksforGeeks" [(visible)]="gfg">
    <p>I am Bottom!</p>
</p-dialog>
  
<p-dialog position="left"
    header="GeeksforGeeks" [(visible)]="gfg">
    <p>I am Left!</p>
</p-dialog>
  
<p-dialog position="right"
    header="GeeksforGeeks" [(visible)]="gfg">
    <p>I am Right!</p>
</p-dialog>




import { Component } from '@angular/core';
import { PrimeNGConfig } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
  
export class AppComponent {
    constructor(private primengConfig: PrimeNGConfig) {}
    gfg: boolean;
      
    ngOnInit() {
      this.primengConfig.ripple = true;
    }
    GFG() {
        this.gfg = true;
    }
}




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

Output:

 

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


Article Tags :