Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Change Color of Progress Bar Angular Directive

I want to integrate angular progress directive in my application.

I found progress bar directive that solve the purpose but I'm not able to change the color of progress bar. I want to give custom color for progress bar.

Does anyone have any idea on this ?

<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
    <script src="example.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<div ng-controller="ProgressDemoCtrl">

    <h3>Static</h3>
    <div class="row">
        <div class="col-sm-4"><progressbar value="55"></progressbar></div>
        <div class="col-sm-4"><progressbar class="progress-striped" value="22" type="warning">22%</progressbar></div>
        <div class="col-sm-4"><progressbar class="progress-striped active" max="200" value="166" type="danger"><i>166 / 200</i></progressbar></div>
    </div>

    <hr />
    <h3>Dynamic <button class="btn btn-sm btn-primary" type="button" ng-click="random()">Randomize</button></h3>
    <progressbar max="max" value="dynamic"><span style="color:black; white-space:nowrap;">{{dynamic}} / {{max}}</span></progressbar>

    <small><em>No animation</em></small>
    <progressbar animate="false" value="dynamic" type="success"><b>{{dynamic}}%</b></progressbar>

    <small><em>Object (changes type based on value)</em></small>
    <progressbar class="progress-striped active" value="dynamic" type="{{type}}">{{type}} <i ng-show="showWarning">!!! Watch out !!!</i></progressbar>

    <hr />
    <h3>Stacked <button class="btn btn-sm btn-primary" type="button" ng-click="randomStacked()">Randomize</button></h3>
    <progress><bar ng-repeat="bar in stacked track by $index" value="bar.value" type="{{bar.type}}"><span ng-hide="bar.value < 5">{{bar.value}}%</span></bar></progress>

</div>
  </body>
</html>

Plunker Link: http://plnkr.co/edit/3AIJPQzQgosmlXV3QQ9D?p=preview

like image 538
Aamir Khan Avatar asked Jun 10 '15 19:06

Aamir Khan


2 Answers

Extending this answer, you can change the color of a Angular UI Progressbar using the following "hacky" method:

<uib-progressbar value="10" type="purple"></uib-progressbar>

this will generate a class .progress-bar-purple

which you can define as a css rule

.progress-bar-purple {
    background-color: purple;
}
like image 110
Jonathan La'Fey Avatar answered Nov 09 '22 08:11

Jonathan La'Fey


You can change the color from a predefined one to another by changing the type attribute of the <progressbar/> directive.

<progressbar class="progress-striped" value="22" type="warning">22%</progressbar>

From the doc:

(Default: null) : Style type. Possible values are 'primary', 'info', 'success', 'warning', 'danger'.

Then you can customize these colors by directly overriding them in your project source code or by generating a custom build in this page

like image 20
Freezystem Avatar answered Nov 09 '22 09:11

Freezystem