Tips for Modifying the Color of a Progress Bar with Angular Directive

I am trying to incorporate an angular progress directive into my application.

Although I have found a progress bar directive that serves the purpose, I am struggling to modify the color of the progress bar. I would like to assign a custom color to the progress bar.

Does anyone have any suggestions on how to achieve 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

Answer №1

Building upon the solution provided in this thread, you have the ability to modify the color of an Angular UI Progressbar with a slightly unconventional approach:

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

This method will result in the creation of a CSS class .progress-bar-purple

which can then be styled according to your preferences using the following css declaration:

.progress-bar-purple {
    background-color: purple;
}

Answer №2

To switch the color of a predefined element, simply adjust the type attribute within the <progressbar/> directive.

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

According to the documentation:

(Default: null) : Specifies the style type. Options include 'primary', 'info', 'success', 'warning', 'danger'.

You can further customize these colors either by directly modifying them in your project's source code or by creating a custom build on this site.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is there a way to prevent my <div> from scrolling when the mouse hovers over it?

I currently have a div that is set to scroll infinitely using JavaScript: <script language="javascript"> i = 0 var speed = 1 function scroll() { i = i + speed var div = document.getElementById("content") div.scrol ...

The input field or help text fails to change to a red color when the field contains invalid information

Previously, I developed an Angular 2/4 application using Bootstrap 3 and Reactive Forms for field validation. In this setup, when there was an error in input fields, the border of the field turned red and an error message would display below the field in r ...

If the option is not chosen, remove the requirement for it

I am in the process of creating a form that offers 3 different payment options: 1 - Direct Deposit 2 - Credit Card 3 - Cash at Office The issue I am facing is with the validation of input fields for Credit Cards. I want to make it so that these field ...

Tips for choosing a class using ng-if

Looking for a solution regarding my use of ng-repeat: HTML: <td class="border" data-ng-repeat="price in goHead.prices track by $index"> In the context of my <td>, I want to apply the class border if data-ng-if="price.isMinPrice" is true, oth ...

Expert tips for adding spacing between images in carousel sliders and eliminating glitches during slides

After creating a carousel following the guidance of this source and initially sharing it on this platform, I encountered an issue with the padding on the first image. As a solution, I removed the padding from the first image, but this caused the image to b ...

Steps for adding products to your shopping cart without using a JavaScript framework:

As a newcomer to web development, I took on the challenge of creating an e-commerce website using only HTML, CSS, and vanilla JavaScript (without any frameworks). I've encountered a roadblock while trying to implement the "Add to Cart" functionality ...

Tips for expanding the progress bar limit in Bootstrap 3

Recently, I encountered an issue with the width of a Progressbar in Bootstrap. The problem arose when I tried to combine the values of three progress bars into one, resulting in a total that exceeded 100%. For example: - ProgressBar 1: 25% - ProgressBar ...

Exploring the combination of Tailwind CSS variants with Framer Motion capabilities

Is it possible to integrate tailwind css classes with framer motion objects effectively? const variant = { hidden: { 'w-0' }, visible: { width: 400, transition: { type: 'spring', stiffness: ...

Using PHP to extract specific content from an HTML page within a div element

I've been working on embedding a section of a website into my own site for security reasons. Unfortunately, I can't reveal the specific website I'm trying to embed, so let's use bbc.co.uk as an example. Here is the PHP/HTML code: < ...

tips on toggling div visibility based on data filtering

<script> function toggleContent(str) { if(str == 'recent' || str == 'old' && !($(".main_content").is(':visible'))) { $(".main_content").show(); } else if( str == 'newComment') { ...

Various Overlay Shapes in Bootstrap Using CSS

So I'm in the process of styling my landing page with CSS based on a design I have in Figma. The page is using Bootstrap 5 as its framework, though I'm not sure if that detail matters in this case. I believe it's definitely doable, but I&apo ...

Is it possible to create an HTML textarea that supports HTML formatting?

Is it possible to have HTML tag support in an HTML textarea within a form, similar to what is seen on Stack Overflow when asking a question? I would like to be able to capture the user's input in a textarea using PHP and print exactly what the user ty ...

Utilizing effective CSS media queries within an Angular application

According to what I've read, it is not recommended in Angular to use the CSS hidden element to hide an element like this: .container{ background-color : powderblue; height : 50px; width : 100% } @media (max-width: 400px){ .container{ ...

Numerous sections with tabs on the webpage

I am in need of incorporating multiple tabbed sections on a single page, but unfortunately they are currently interconnected. When one tab is clicked, it impacts the others. To see this issue in action, you can visit: https://jsfiddle.net/pxpsvoc6/ This ...

The Angular routing feature seems to be malfunctioning as the URL is showing up but the page fails to load

After including angular.min.js and angular-route.min.js I encountered an issue where clicking the login button would change the URL to '/home', but the home.html page wouldn't load. I attempted adding a controller under templateUrl, but it ...

What are the best ways to ensure that my side menu, bottom buttons, and content are all responsive

I have been struggling with creating a responsive side menu in my HTML code. Despite my efforts, the side menu contents, buttons, and layout do not adjust properly when resizing the browser window. When I drag the browser size from bottom to top, the butto ...

What is the best way to accomplish a smooth transition of background colors similar to this design

I was browsing different websites and stumbled upon this amazing background color transition that caught my attention. I really liked it and now I want to create something similar on my own website. Despite my best efforts, I haven't been able to achi ...

The controller is encountering an error due to a function that is not defined within the services

amcApp.service('utilService', function ($http, $q,$rootScope) { var fetchSupportTypes = function () { var deferredPromise = $q.defer(); $http.get($rootScope.BaseUrl+'vendor/supportTypes') .then(function ...

How do you use CSS and Bootstrap to create a background image that covers one-third of the screen's size?

I have attempted to implement the following using inline CSS along with Bootstrap, but unfortunately it is not functioning correctly. <div class="container" class="img-responsive" class="img-fluid" style="background-image: url('img/projects_cover. ...

Encountering a 404 server error on Azure Node.js web app while running AngularJS 1.6.x with lengthy URLs

My current setup includes two azure web apps deployed with a node.js express server and using angularjs (1.6.x) for the MVC (ui-router). One web app links directly to the other, passing an access token in the query params for authentication. Everything run ...