Open In App

Angular PrimeNG Dialog Positioning

Last Updated : 19 Aug, 2022
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 Dialog Positioning in Angular PrimeNG. We will also learn about the properties along with their syntaxes that will be used in the code.

Dialog component is used to make a component containing some content to display in an overlay window. The position property, with the default value of center, controls where the dialogue appears. Top, bottom, left, right, top-left, top-right, bottom-left, and bottom-right are additional acceptable values. If the content or location of the dialogue changes, you can also reposition it by using the resetPosition() function of Dialog.

Angular PrimeNG Dialog Positioning Properties:

  • header: It is the title text of the dialog. It is of string data type, the default value is null.
  • position: It is used to set the position of the dialog. It is of string data type, the default value is center.
  • visible: It specifies the visibility of the dialog. It is of the boolean data type, the default value is false.
  • styleClass: It is used to set the style class of the component. It is of string data type, the default value is null.

Syntax:

<p-dialog 
      position="..." 
      header="...." 
      [(visible)]="...">
      ......
</p-dialog>

<p-button 
      (click)="..." 
      label="....">
</p-button>

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:

 

  • Run the below command to see the output.
ng serve --open

Example 1: Below is the code example that illustrates the use of  Angular PrimeNG Dialog Positioning using the left and right positioning.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>PrimeNG Dialog Positioning</h5>
  
    <p-dialog position="left" 
              header="GeeksforGeeks" 
              [(visible)]="geeks1">
        <p>Left Dialog Positioning</p>
    </p-dialog>
  
    <p-dialog position="right" 
              header="GeeksforGeeks" 
              [(visible)]="geeks2">
        <p>Right Dialog Positioning</p>
    </p-dialog>
  
    <p-button (click)="gfg1()" 
              label="Left Positioning" 
              styleClass="p-mr-2">
    </p-button>
  
    <p-button (click)="gfg2()" 
              label="Right Positioning">
    </p-button>
</div>


app.component.ts




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) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
  geeks1: boolean;
  geeks2: boolean;
  
  gfg1() {
    this.geeks1 = true;
  }
  
  gfg2() {
    this.geeks2 = true;
  }
}


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 { 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 code example that illustrates the use of  Angular PrimeNG Dialog Positioning using the top and bottom positioning.

app.component.html




<div style="text-align: center">
    <h2 style="color: green">GeeksforGeeks</h2>
    <h5>PrimeNG Dialog Positioning</h5>
  
    <p-dialog position="top" 
              header="GeeksforGeeks" 
              [(visible)]="geeks1">
        <p>Top Dialog Positioning </p>
    </p-dialog>
  
    <p-dialog position="bottom" 
              header="GeeksforGeeks" 
              [(visible)]="geeks2">
        <p>Bottom Dialog Positioning</p>
    </p-dialog>
  
    <p-button (click)="gfg1()" 
              label="Top Positioning" 
              styleClass="p-mr-2">
    </p-button>
  
    <p-button (click)="gfg2()" 
              label="Bottom Positioning">
    </p-button>
</div>


app.component.ts




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) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
  geeks1: boolean;
  geeks2: boolean;
  
  gfg1() {
    this.geeks1 = true;
  }
  
  gfg2() {
    this.geeks2 = true;
  }
}


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



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

Similar Reads