Angular PrimeNG BlockUI Styling
Last Updated :
24 Jan, 2023
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 BlockUI Styling in Angular PrimeNG.
The BlockUI component is used to block the component or the whole page. The Styling classes are used to add styles on the BlockUI components.
Angular PrimeNG BlockUI Styling:
- p-blockui: It is the mask element.
- p-blockui-document: It is the mask element in full-screen mode.
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: This is the basic example that illustrates how to use Angular PrimeNG BlockUI Styling.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG BlockUI Styling</ h5 >
< button
pButton
class = "mb-4"
label = "Block the Panel"
(click)="tempBlock()">
</ button >
< br >< br >
< p-panel #blockTarget header = "About GFG" >
< p >
GeeksforGeeks is a portal for 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 >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
blocked: boolean = false ;
time = 1;
tempBlock() {
this .blocked = true ;
setTimeout(() => {
this .blocked = false ;
}, this .time * 1000);
}
}
|
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 { }
|
CSS
:host ::ng-deep .custom-content{
color : white ;
background-color : green ;
border-radius: 10px ;
padding : 30px ;
}
|
Output:
Example 2: This is another basic example that illustrates how to use Angular PrimeNG BlockUI Styling using the tempUnblock function.
HTML
< h1 style = "color: green" >GeeksforGeeks</ h1 >
< h5 >Angular PrimeNG BlockUI Styling</ h5 >
< button
pButton
class = "mb-4"
label = "Block the Panel"
(click)="tempBlock()">
</ button >
< button type = "button" pButton
pRipple label = "Unblock the Panel"
(click)="tempUnblock()">
</ button >
< br >< br >
< p-panel #blockTarget header = "About GFG" >
< p >
GeeksforGeeks is a portal for 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 >
|
Javascript
import { Component } from '@angular/core' ;
@Component({
selector: 'app-root' ,
templateUrl: './app.component.html' ,
styleUrls: [ './app.component.css' ]
})
export class AppComponent {
blocked: boolean = false ;
time = 5;
tempBlock() {
this .blocked = true ;
setTimeout(() => {
this .blocked = false ;
}, this .time * 1000);
}
tempUnblock(){
this .blocked = false ;
}
}
|
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 { }
|
CSS
:host ::ng-deep .p-panel{
color : white ;
background-color : green ;
border-radius: 10px ;
padding : 40px ;
}
:host ::ng-deep .custom-content{
color : black ;
background-color : rgb ( 130 , 230 , 130 );
border-radius: 20px ;
padding : 40px ;
}
|
Output:
Reference: https://primefaces.org/primeng/blockui
Share your thoughts in the comments
Please Login to comment...