Open In App

Angular PrimeNG BlockUI Properties

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 learn how to use BlockUI Properties in Angular PrimeNG. We will also learn about the properties, along with their syntaxes that will be used in the code.

The BlockUI Component is used to block the component or the whole page.



Angular PrimeNG BlockUI Properties:

 



Syntax:

<p-blockUI [blocked]="blocked">
    ...
</p-blockUI>

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: After complete installation, it will look like the following:

 

ng serve --save

Example 1: This is the basic example that shows how to use Angular PrimeNG BlockUI Properties.




<h2 style="color: green">GeeksforGeeks</h2>
<h5>Angular PrimeNG BlockUI Properties</h5>
  
<button type="button"
        pButton
        pRipple
        label="Block"
        (click)="gfg=true">
</button>
<button type="button"
        pButton
        pRipple
        label="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="GeeksforGeeks" 
                 styleClass="p-mt-4">
    <p class="p-m-0">
        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>




import { Component } from "@angular/core";
  
@Component({
    selector: "app-root",
    templateUrl: "./app.component.html",
})
  
export class AppComponent {
    gfg: boolean = false;
}




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { BlockUIModule } from 'primeng/blockui';
import { PanelModule } from 'primeng/panel';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        BlockUIModule,
        ButtonModule,
        PanelModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

Output:

 

Example 2: This is another basic example that shows how to use Angular PrimeNG BlockUI Properties.




<h2 style="color: green">GeeksforGeeks</h2>
<h3>Angular PrimeNG BlockUI Properties</h3>
  
<button pButton
        class="mb-4"
        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>




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




import { NgModule } from '@angular/core';
import { BrowserModule } 
    from '@angular/platform-browser';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { BlockUIModule } from 'primeng/blockui';
import { PanelModule } from 'primeng/panel';
import { ButtonModule } from 'primeng/button';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        BlockUIModule,
        ButtonModule,
        PanelModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
})
export class AppModule { }

Output:

 

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


Article Tags :