1

i would like to know how can we make a progress bar change its color as the percentage value increases.

I want the progress bar to show a red(danger) until 33%. Then turn blue upto 66% and then turn green until 100%. Can this be done using angular js?

1
  • 1
    show some code! what did you try? what isn't working? Commented Apr 4, 2014 at 14:36

2 Answers 2

2

Use ng-class.

ui.bootstrap has a good example of this for its rating control, using this technique:

ng-class="{'label-warning': percent<33, 'label-info': percent>=33 && percent<66, 'label-success': percent>=66}"

This works for progress bars as well. You just need to define percent somewhere. http://plnkr.co/iBliMPYnWbsJJCtzqWTu

Update:
Here are classes intended for bootstrap progress bars:

ng-class="{'progress-bar-danger': percent<33, 'progress-bar-info': percent>=33 && percent<66, 'progress-bar-success': percent>=66}"
Sign up to request clarification or add additional context in comments.

5 Comments

haha that was clever to use that code. But the colors are not changing
Try the plunk now. Maybe progress bar need progress bar classes only?
Hi i would like some help with this question. Could you help? Thanks stackoverflow.com/questions/23161742/…
Sure, i'll look at it tonight.
2

Well you can use angular-ui bootstrap's <progressbar> directive. The colors that you suggest for the percentages exists in their collection of colors to be assigned as types in a specific state of the progress that you define. These state definitions such as the change in color from a specific value percentage can be manipulated in your controllers. Simply follow the angular-ui implementation with their <progressbar> directive.

1 Comment

very nice. i guess you can use type if you want controller to manage it, instead of ng-class.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.