Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update bootstrap progress bar.

The documentation on bootstrap progress bars illustrate how to display a progress bar with default values and completion value, but now how to update it? So, what's the simplest way to go about updating the value and width?

This is my progress bar in file home.html:

<div class="progress">
    <div id="trainingProgressBar" class="progress-bar 
        progress-bar-success progress-bar-striped active" 
        role="progressbar" 
        aria-valuenow="40" aria-valuemin="0" 
        aria-valuemax="100" style="width:40%">
        {{trainingProgress}}% Complete
    </div>
</div>

and in my home.ts file I declare my trainingProgress value:

public trainingProgress: number = 10;

The text will change to whatever trainingProgress is, but the width will not because trainingProgress isn't linked to aria-valuenow and width:%.

like image 531
Roka545 Avatar asked Jul 19 '16 16:07

Roka545


People also ask

What is a bootstrap progress bar?

Documentation and examples for using Bootstrap custom progress bars featuring support for stacked bars, animated backgrounds, and text labels. Progress components are built with two HTML elements, some CSS to set the width, and a few attributes.

How do I create a default progress bar using CSS?

To create a default progress bar, add a .progress class to a container element and add the .progress-bar class to its child element. Use the CSS width property to set the width of the progress bar:

How do I set the max value of the progress-bar?

We use the .progress as a wrapper to indicate the max value of the progress bar. We use the inner .progress-bar to indicate the progress so far. The .progress-bar requires an inline style, utility class, or custom CSS to set their width. The .progress-bar also requires some role and aria attributes to make it accessible.

How to add multiple progress bars in a progress component?

Include multiple progress bars in a progress component if you need. Add .progress-bar-striped to any .progress-bar to apply a stripe via CSS gradient over the progress bar’s background color. The striped gradient can also be animated. Add .progress-bar-animated to .progress-bar to animate the stripes right to left via CSS3 animations.


1 Answers

Use attribute and style binding:

<div class="progress">
    <div id="trainingProgressBar" class="progress-bar 
        progress-bar-success progress-bar-striped active" 
        role="progressbar" 
        aria-valuemin="0" 
        aria-valuemax="100" 
        [attr.aria-valuenow]="trainingProgress" 
        [style.width.%]="trainingProgress">
        {{trainingProgress}}% Complete
    </div>
</div>

Here the PLUNKER

like image 140
Alexander Kravets Avatar answered Nov 11 '22 10:11

Alexander Kravets