Open In App

Angular PrimeNG ProgressBar Component

Last Updated : 08 Sep, 2021
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 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:

  • value: It specifies the current value of the progress. It accepts a number data type, the default value is null.
  • showValue: It specifies whether to show or hide progress bar value. It is of the boolean data type, the default value is true.
  • unit: It specifies the Unit sign appended to the value. It is of string data type, the default value is %.
  • mode: It specifies the mode of the progress, the valid values are “determinate” and “indeterminate”. It is of string data type, the default value is determinate.

Styling:

  • p-progressbar: It is the container element.
  • p-progressbar-determinate: It is the container element of a determinate progressbar.
  • p-progressbar-indeterminate: It is the container element of an indeterminate progressbar.
  • p-progressbar-value: It is the element whose width changes according to value.
  • p-progressbar-label: It is the label element that displays the current value.

 

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.

app.component.html




<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>


app.component.ts




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


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 { 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.

app.component.html




<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>


app.component.ts




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);
  }
}


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 { 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



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

Similar Reads