Open In App

Angular PrimeNG ProgressBar Component

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 progressBar component in Angular PrimeNG. We will also learn about the properties, styling along with their syntaxes that will be used in the code. 

ProgressBar component: It is used to make a bar that displays the process status.



Properties:

Styling:



 

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:

 

Example 1: This is the basic example that illustrates how to use the ProgressBar component.




<h2>GeeksforGeeks</h2>
<h5>PrimeNG ProgressBar Component</h5>
<h5>Static Progress Bar</h5>
<p-progressBar [value]="30"></p-progressBar>
<h5>Indeterminate Progress Bar</h5>
<p-progressBar mode="indeterminate" 
               [style]="{'height': '6px'}">
</p-progressBar>




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {}




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 { ProgressBarModule } from 'primeng/progressbar';
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    ProgressBarModule,
    FormsModule
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}

Output:

Example 2: In this example, we will make the dynamic progressbar component that will update randomly along with displaying with & without the progress status value.




<h1>GeeksforGeeks</h1>
<h4>PrimeNG ProgressBar Component</h4>
<div class="card">
  <h5>Dynamic (with status value)</h5>
  <p-progressBar [value]="gfg1"></p-progressBar>
  <h5>Dynamic (without status value)</h5>
  <p-progressBar [showValue]='false' [value]="gfg2"></p-progressBar>
</div>




import { Component } from '@angular/core';
  
@Component({
  selector: 'my-app',
  templateUrl: './app.component.html'
})
export class AppComponent {
  gfg1: number = 0;
  gfg2: number = 0;
  
  ngOnInit() {
    setInterval(() => {
      this.gfg1 = this.gfg1 + Math.floor(Math.random() * 10) + 1;
      if (this.gfg1 >= 100) {
        this.gfg1 = 100;
      }
    }, 1500),
      setInterval(() => {
        this.gfg2 = this.gfg2 + Math.floor(Math.random() * 10) + 3;
        if (this.gfg2 >= 100) {
          this.gfg2 = 100;
        }
      }, 1500);
  }
}




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 { ProgressBarModule } from 'primeng/progressbar';
  
  
@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    ProgressBarModule,
    FormsModule
  ],
  declarations: [AppComponent],
  bootstrap: [AppComponent]
})
export class AppModule {}

Output:

Reference: https://primefaces.org/primeng/showcase/#/progressbar


Article Tags :