Open In App

Angular PrimeNG Dialog Position

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 Position 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 Position Properties:

Syntax:



<p-dialog
    header="..."
    [(visible)]="..."
    [position]="...">
    .....
</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:

 

ng serve --open

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




<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Dialog Position</h5>
  
  <p-button
        (click)="showPosPos('left')"
        label="Left Dialog Position"
        styleClass="p-mr-3">
  </p-button>
  
  <p-button
        (click)="showPosPos('right')"
        label="Right Dialog Position">
  </p-button>
  
  <p-dialog
        header="GeeksforGeeks"
        [(visible)]="displayPos"
        [position]="pos">
        <p>
            GeeksforGeeks is a Computer Science 
            Portal and we are learning Angular
            PrimeNG Dialog Position here.
        </p>
  
  
        <ng-template pTemplate="footer">
            <p-button
                  styleClass="p-button-success"
                  (click)="displayPos = false"
                  label="Ok">
            </p-button>
  
            <p-button
                  styleClass="p-button-danger"
                  (click)="displayPos = false"
                  label="Cancel">
            </p-button>
        </ng-template>
  </p-dialog>
</div>




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styles: [],
})
export class AppComponent {
  constructor(private primengConfig: PrimeNGConfig) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
  
  displayPos: boolean;
  pos: string;
  
  showPosPos(pos: string) {
    this.pos = pos;
    this.displayPos = 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 code example that illustrates the use of  Angular PrimeNG Dialog Position using the top and bottom positions.




<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Dialog Position</h5>
  
  <p-button
        (click)="showPosPos('top')"
        label="Top Dialog Position"
        styleClass="p-mr-3">
  </p-button>
  
  <p-button
        (click)="showPosPos('bottom')"
        label="Bottom Dialog Position">
  </p-button>
  
  <p-dialog
        header="GeeksforGeeks"
        [(visible)]="displayPos"
        [position]="pos">
        <p>
          GeeksforGeeks is a Computer Science 
          Portal and we are learning Angular
          PrimeNG Dialog Position here.
        </p>
  
  
        <ng-template pTemplate="footer">
              <p-button
                    styleClass="p-button-success"
                    (click)="displayPos = false"
                    label="Ok">
              </p-button>
  
              <p-button
                    styleClass="p-button-danger"
                    (click)="displayPos = false"
                    label="Cancel">
              </p-button>
        </ng-template>
  </p-dialog>
</div>




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styles: [],
})
export class AppComponent {
  constructor(private primengConfig: PrimeNGConfig) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
  
  displayPos: boolean;
  pos: string;
  
  showPosPos(pos: string) {
    this.pos = pos;
    this.displayPos = 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 3: Below is another code example that illustrates the use of Angular PrimeNG Dialog Position using the top-left, top-right, bottom-left, and bottom-right positions.




<div style="text-align: center">
  <h2 style="color: green">GeeksforGeeks</h2>
  <h5>Angular PrimeNG Dialog Position</h5>
  
  <p-button
        (click)="showPosPos('top-left')"
        label="Top Left Dialog Position">
  </p-button>
  
  <p-button
        (click)="showPosPos('top-right')"
        label="Top-Right Dialog Position"
        styleClass="p-mx-3">
  </p-button>
  
  <p-button
        (click)="showPosPos('bottom-left')"
        label="Bottom-Left Dialog Position"
        styleClass="p-mr-3">
  </p-button>
  
  <p-button
        (click)="showPosPos('bottom-right')"
        label="Bottom-Right Dialog Position">
  </p-button>
  
  <p-dialog
        header="GeeksforGeeks"
        [(visible)]="displayPos"
        [position]="pos"
        [style]="{width: '30vw'}" >
        <p>
            GeeksforGeeks is a Computer Science 
            Portal and we are learning Angular
            PrimeNG Dialog Position here.
        </p>
  
  
        <ng-template pTemplate="footer">
              <p-button
                    styleClass="p-button-success"
                    (click)="displayPos = false"
                    label="Ok">
              </p-button>
  
              <p-button
                    styleClass="p-button-danger"
                    (click)="displayPos = false"
                    label="Cancel">
              </p-button>
        </ng-template>
  </p-dialog>
</div>




import { Component } from "@angular/core";
import { PrimeNGConfig } from "primeng/api";
  
@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  styles: [],
})
export class AppComponent {
  constructor(private primengConfig: PrimeNGConfig) {}
  
  ngOnInit() {
    this.primengConfig.ripple = true;
  }
  
  displayPos: boolean;
  pos: string;
  
  showPosPos(pos: string) {
    this.pos = pos;
    this.displayPos = 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 :