Angular PrimeNG BlockUI Component - GeeksforGeeks

24 Aug, 2021
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 the BlockUI component in Angular PrimeNG.
BlockUI component: It is used to block the component or the whole page.
Properties:
blocked: It is used to control the blocked state. It is of the boolean data type, the default value is false.
target: It is used to define the name of the local ng-template variable referring to another component. It is of string data type, the default value documents.
baseZIndex: It is used to define the base z-Index value to use in layering. It is of number data type, the default value is 0.
autoZIndex: It is used to whether to automatically manage the layering. It is of boolean data type, the default value is true.
styleClass: It is used to define the style class of the component. It is of string data type, the default value is false.
Styling:
p-blockui: It is the masking element.
p-blockui-document: It is the masking element in full-screen mode.
 
Creating Angular application & module installation:
Step 1: Create an Angular application using the following command.ng new appname
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 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
Step 3: Install PrimeNG in your given directory.
npm install primeng --save
npm install primeicons --save
Project Structure: It will look like the following:
 
Example 1: This is the basic example that shows how to use the blockUI component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG BlockUI Component</h5><p-blockUI [blocked]="gfg"></p-blockUI>  <button  type="button"  pButton  pRipple  label="Click here to block"  (click)="geeks()"></button>
app.component.ts
import { Component } from "@angular/core";  @Component({  selector: "app-root",  templateUrl: "./app.component.html",})export class AppComponent {  gfg: boolean = false;    geeks() {    this.gfg = true;    setTimeout(() => {      this.gfg = false;    }, 3000);  }}
app.module.ts
import { NgModule } from "@angular/core";import { BrowserModule } from "@angular/platform-browser";import { FormsModule } from "@angular/forms";import { BrowserAnimationsModule }     from "@angular/platform-browser/animations";  import { AppComponent } from "./app.component";import { ButtonModule } from "primeng/button";import { BlockUIModule } from "primeng/blockui";import { PanelModule } from "primeng/panel";  @NgModule({  imports: [    BrowserModule,    BrowserAnimationsModule,    BlockUIModule,    ButtonModule,    PanelModule,    FormsModule,  ],  declarations: [AppComponent],  bootstrap: [AppComponent],})export class AppModule {}
Output:
Example 2: In this example, we will know how to block a panel in the message component.
app.component.html
<h2>GeeksforGeeks</h2><h5>PrimeNG BlockUI Component</h5>  <button  type="button"  pButton  pRipple  label="Click Here to Block"  (click)="gfg=true"></button><button  type="button"  pButton  pRipple  label="Click Here to Unblock"  (click)="gfg=false"></button>  <p-blockUI [target]="geeks" [blocked]="gfg">  <i class="pi pi-lock" style="font-size: 3rem"></i></p-blockUI><p-panel #geeks header="BlockUI" styleClass="p-mt-4">  <p class="p-m-0">    Angular PrimeNG is a framework used with     angular to create components with    great styling and this framework is very     easy to use and is used to make    responsive websites.  </p>  </p-panel>
app.component.ts
import { Component } from "@angular/core";  @Component({  selector: "app-root",  templateUrl: "./app.component.html",})export class AppComponent {  gfg: boolean = false;}
app.module.ts
import { NgModule } from "@angular/core";import { BrowserModule } from "@angular/platform-browser";import { FormsModule } from "@angular/forms";import { BrowserAnimationsModule }     from "@angular/platform-browser/animations";  import { AppComponent } from "./app.component";import { ButtonModule } from "primeng/button";import { BlockUIModule } from "primeng/blockui";import { PanelModule } from "primeng/panel";  @NgModule({  imports: [    BrowserModule,    BrowserAnimationsModule,    BlockUIModule,    ButtonModule,    PanelModule,    FormsModule,  ],  declarations: [AppComponent],  bootstrap: [AppComponent],})export class AppModule {}
Output:
Reference: https://primefaces.org/primeng/showcase/#/blockui
Angular-PrimeNG
AngularJS
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Angular PrimeNG Dropdown Component
Angular PrimeNG Calendar Component
Angular PrimeNG Messages Component
Angular 10 (blur) Event
How to make a Bootstrap Modal Popup in Angular 9/8 ?
Remove elements from a JavaScript Array
Installation of Node.js on Linux
Convert a string to an integer in JavaScript
How to fetch data from an API in ReactJS ?
How to insert spaces/tabs in text using HTML/CSS?