Open In App

Angular PrimeNG BlockUI Methods

Last Updated : 31 Jan, 2023
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 the BlockUI Methods in Angular PrimeNG.

The BlockUI Component is used to block the component or the whole page. The methods have different functionality and we can alter the BlockUI component according to the use case.

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:

 

Steps to run the application: Run the below command to see the output

ng serve --save

Example 1: Below is the example code that illustrates the use of Angular PrimeNG BlockUI Methods to block the whole document.

  • app.component.html:

HTML




<h1 style="color: green">GeeksforGeeks</h1>
<h5>Angular PrimeNG BlockUI Methods</h5>
  
<p-blockUI 
    [blocked]="geekDocumentBlock">
</p-blockUI>
  
<button 
    type="button" 
    class="p-button-success" 
    icon="pi pi-code" pButton 
    pRipple label="Click me Geek!" 
    (click)="GeekBlock()">
</button>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html'
})
  
export class AppComponent { 
    geekPanelBlock: boolean = false;
    geekDocumentBlock: boolean = false;
          
    GeekBlock() {
        this.geekDocumentBlock = true;
        setTimeout(() => {
            this.geekDocumentBlock = false;
        }, 3000);
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
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: [
        BrowserAnimationsModule,
        BlockUIModule,
        ButtonModule,
        PanelModule,
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Example 2: Below is another example code that illustrates the use of Angular PrimeNG BlockUI Methods to block the Panel.

  • app.component.html:

HTML




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG BlockUI Methods</h3>
  
<button pButton
        icon="pi pi-code"
        class="mb-4 p-button-success"
        label="Block the Panel Geek"
        (click)="tempBlock()">
</button>
<br/><br/>
<p-panel #blockTarget header="GeeksforGeeks">
    <p>
        GeeksforGeeks It is a Computer
        Science portal for all geeks.
        Here you can share your knowledge
        with other geeks through articles.
        There are also many courses which
        provides you industry ready skills
        in affordable pricing.
    </p>
</p-panel>
  
<p-blockUI [target]="blockTarget"
     [blocked]="blocked">
    <div class="text-center custom-content">
        <i class="pi pi-lock"></i>
        <p>The panel is blocked for {{time}} seconds</p>
    </div>
</p-blockUI>


  • app.component.ts:

Javascript




import { Component } from '@angular/core';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
    styles: [
        `.custom-content{
            color: black;
            background-color: cyan;
            padding: 15px;
        }`
    ]
})
  
export class AppComponent {
    blocked: boolean = false;
    time = 2;
  
    tempBlock() {
        this.blocked = true;
        setTimeout(() => {
            this.blocked = false;
        }, this.time * 1000);
    }
}


  • app.module.ts:

Javascript




import { NgModule } from '@angular/core';
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: [
        BrowserAnimationsModule,
        BlockUIModule,
        ButtonModule,
        PanelModule,
    ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
  
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/blockui



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

Similar Reads