BlockUIBlockUI can either block other components or the whole page.

BlockUI - 图1

Documentation

Import

  1. import {BlockUIModule} from 'primeng/blockui';
  2.  

Getting Started

BlockUI is controlled using the blocked property and component to block is defined as target. If target is not provided, document itself is selected as the block target.

  1. export class BlockUIDemo {
  2. blocked: boolean;
  3. }
  4.  
  1. <p-blockUI [blocked]="blocked"></p-blockUI>
  2.  

To block a certain component, define a local ng-template variable and bind it to the target option. The target component must implement the BlockableUI interface, otherwise an exception is thrown.

  1. <p-blockUI [blocked]="blockedDocument" [target]="pnl"></p-blockUI>
  2. <p-panel #pnl header="Panel Header">
  3. Content of Panel
  4. </p-panel>
  5.  

Custom Content

Blocker mask is customized by simply adding the content inside the component

  1. <p-blockUI [target]="pnl" [blocked]="blockedPanel">
  2. <i class="fa fa-lock fa-5x" style="position:absolute;top:25%;left:50%"></i>
  3. </p-blockUI>
  4. <p-panel #pnl header="Panel Header">
  5. Content of Panel
  6. </p-panel>
  7.  

Properties

NameTypeDefaultDescription
blockedbooleanfalseControls the blocked state.
targetanydocumentName of the local ng-template variable referring to another component.
baseZIndexnumber0Base zIndex value to use in layering.
autoZIndexbooleantrueWhether to automatically manage layering.

Styling

Following is the list of structural style classes, for theming classes visit theming page.

NameElement
ui-blockuiContainer element.

Dependencies

None.

Source

View on GitHub

  1. export class BlockUIDemo {
  2. blockedPanel: boolean = false;
  3. blockedDocument: boolean = false;
  4. blockDocument() {
  5. this.blockedDocument = true;
  6. setTimeout(() => {
  7. this.blockedDocument = false;
  8. }, 3000);
  9. }
  10. }
  11.  
  1. <h3 class="first">Document</h3>
  2. <p-blockUI [blocked]="blockedDocument"></p-blockUI>
  3. <button type="button" pButton label="Block" (click)="blockDocument()"></button>
  4. <h3>Panel</h3>
  5. <button type="button" pButton label="Block" (click)="blockedPanel=true"></button>
  6. <button type="button" pButton label="Unblock" (click)="blockedPanel=false"></button>
  7. <p-blockUI [target]="pnl" [blocked]="blockedPanel">
  8. <i class="fa fa-lock fa-5x" style="position:absolute;top:25%;left:50%"></i>
  9. </p-blockUI>
  10. <p-panel #pnl header="Godfather I" [style]="{'margin-top':'20px'}">
  11. The story begins as Don Vito Corleone, the head of a New York Mafia family, oversees his daughter's wedding.
  12. His beloved son Michael has just come home from the war, but does not intend to become part of his father's business.
  13. Through Michael's life the nature of the family business becomes clear. The business of the family is just like the head of the family,
  14. kind and benevolent to those who give respect, but given to ruthless violence whenever anything stands against the good of the family.
  15. </p-panel>
  16.