Search code examples
angularprimeng

How to Make a Button in the Header of Dialog Component in PRIMENG in Angular4


I want to put an button in header of the dialog window in primeng. The link for the code is https://www.primefaces.org/primeng/#/dialog.

The requirement is want to add two buttons(with image or any icon as calculator and quesstion mark) in the right side of top header and these buttons should call a method abc().

Code looks like:-

model.component.html
---------------------
<p-dialog header="top header title pass here" [(visible)]="display" modal="modal" 
draggable="true" dismissableMask="true" positionTop="50" padding="0px" width="1200" 
height="350" [responsive]="true">
   // here two buttons btn1 and btn2(with icons) next to 'fa fa-fw fa-close' icon.
    <p>The stor.</p>
    <p-footer>
        <button type="button" pButton icon="fa-check" (click)="display=false" 
         label="Yes">hghk</button>
    </p-footer>
</p-dialog>

 <button type="button" (click)="showDialog()" pButton icon="fa-external-link-square" 
  label="Show">Lead</button>

model.component.ts
---------------------
  display = false;
  showDialog() {
    this.display = true;
  }

Solution

  • You need to use the p-header attribute of the p-dialog like so:

    <p-dialog [(visible)]="display" modal="modal" draggable="true" dismissableMask="true" positionTop="50" padding="0px" width="1200" height="350" [responsive]="true">
        <p-header>
            top header title pass here
            <button type="button" pButton icon="fa-calculator" (click)="abc()"></button>
            <button type="button" pButton icon="fa-question" (click)="abc()"></button>
        </p-header>
    
        <p>The stor.</p>
    
        <p-footer>
            <button type="button" pButton icon="fa-check" (click)="display=false" label="Yes">hghk</button>
        </p-footer>
    </p-dialog>
    

    You should then be able to add css that floats the buttons to the right of the header.