Customizing colors for the progress bar in Angular Material

In my Angular 5 project, I am using a material progress bar and hoping to customize the colors based on the percentage progress. Despite trying various methods from other sources (including previous SO questions), I have been unsuccessful in getting it to work properly. Here is the snippet of HTML code I am working with:

<mat-progress-bar *ngIf="cell.name === 'progress'" [value]="cell.value" 
    class="mat-progress-bar-round my-color" [ngClass]="'color ' + ((cell.value <= 
     30) ? 'color-red' : (cell.value < 70) ? 'color-yellow' : 'color-green')">   
    </mat-progress-bar>

Below is the corresponding sass (css) code:

   mat-progress-bar {
      &.mat-progress-bar-big {
        padding: 13px 0;
      }

      &.mat-progress-bar-round {
        border-radius: 11px;
        height: 6px;

        .mat-progress-bar-buffer {
          background-color: $grey3;
        }

        .mat-progress-bar-fill {
          &::after {
            border-radius: 11px;
          }
        }

        &.color {
          .mat-progress-bar-fill {
            &::after {
              animation: none;
              content: '';
              display: inline-block;
              left: 0;
            }
          }

          &.color-red {
            ......
          }

          &.color-yellow {
            ......
          }

          &.color-green {
            ......
          }

          &.color-aqua {
            ......
          }
        }
      }
    }

Your assistance in resolving this issue would be greatly appreciated! 😊

Answer â„–1

Click here to view image

/deep/ .mat-progress-bar-fill::after {
    background-color: green;
}

/deep/ .mat-progress-bar-buffer {
    background: #E4E8EB;
}

Answer â„–2

After some testing, I found success by setting the color in the .ts file.

<mat-progress-bar [value]="cell.value"  [color]="cell.color">   
</mat-progress-bar>

In the .ts file, I added the following line:

cell.color = 'primary'; //using predefined color in default theme

If needed, you can easily change 'primary' with your own custom color.

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

Error: Property 'instance' is undefined and cannot be read

Trying to confirm the functionality of the following method: showSnackbar(): void { if (this.modifiedReferences.length) { const snackbar = this.snackbarService.open({ message: '', type: 'success', durat ...

New feature that allows color change to be black or white depending on background color

Can anyone suggest a function from material UI that can automatically change text color to either white or black based on the background color? For example: <AppBar color="primary"> <Toolbar> <Typography color="i ...

Executing functions in TypeScript

I am facing an issue while trying to call a function through the click event in my template. The error message I receive is "get is not a function". Can someone help me identify where the problem lies? This is my template: <button class="btn btn-prima ...

chaotic telerik editor arrangement

I have incorporated the Rad Editor into my ASP.NET page. <asp:ScriptManager ID="ScriptManager1" runat="server"> </asp:ScriptManager> <telerik:RadEditor ID="reSummery" runat="server" > </telerik:RadEditor> Despite not referencing ...

having trouble transferring data from one angular component to another

I've been attempting to send data from one component to another using the service file method. I've created two components - a login component and a home component. The goal is to pass data from the login component to the home component. In the l ...

Vanilla JS Rock, Paper, Scissors Game - Fails to reset classes upon restarting

Many questions have been raised about this particular topic, but a solution for vanilla js seems elusive. Let's delve into a new challenge: Rock paper scissors with vanilla js. The game functions properly on its own, but the issue arises when attemp ...

Separating buttons (two buttons switching on and off simultaneously) and displaying the corresponding button based on the data

My current project involves creating a registration page for specific courses. While I am able to display the information correctly, I am facing an issue with the ng-repeat function. The problem lies in all the Register buttons toggling incorrectly. Additi ...

Unable to transfer information from the Parent component to the Child component

Can you help me solve this strange issue? I am experiencing a problem where I am passing data from a parent component to a child component using a service method that returns data as Observable<DemoModel>. The issue is that when the child component ...

Ensure the column breaks before the element without disrupting the wrapper in CSS

My objective is to always initiate a line break before a specific element, in this case, the h2 tag: https://i.sstatic.net/fy80H.png https://jsfiddle.net/hv0sm40o/3/ html <div class="columns"> <h2>Jelly pastry chocolate cake pastry</h2&g ...

Variety of background colors for different categories

Is there a way to showcase my categories with different background colors using a custom post type? I want to link the slug name from my taxonomy to serve as the class attribute for a span element and style it with CSS. However, I am encountering issues wi ...

retrieve the data attribute of a link within an unordered list

I have been attempting to extract a data attribute from a link within a list when it is clicked on. $(document).on('click', "ul.pagination li a", function(e) { e.preventDefault(); var page = $(this).attr("page"); var article_id = get ...

Transform your CSS styles into Material-UI makestyles

I am looking to implement an IconButton with a website preview feature that appears when the user hovers over the help icon. I came across a similar solution using CSS, but I need to convert it to Material UI. Here is the CSS code that needs to be converte ...

The specified module could not be located in the ngx-toastr library

I'm having trouble finding the solution... ERROR in ./node_modules/ngx-toastr/fesm5/ngx-toastr.js Module not detected: Error: Unable to locate '/Users/vasanthan/Mean projects/node_modules/@angular/animations' in '/Users/vasanthan/Mean ...

Eliminate the unnecessary gap below the image

I have noticed that there is too much space beneath an image on my website. I have tried checking for extra tags, but I suspect that it might be controlled in a css file. Could someone please help me identify which part of the css is causing this extra ...

If a number already exists, create 3 tables using MySQL and PHP

Currently facing an issue, I am in the process of developing a custom registration form for a browser game. I need to assign planets upon registration to users. Here's the breakdown: 9 galaxies, each galaxy consisting of 400 systems with each syste ...

A guide to merging two JSON objects into a single array

Contains two different JSON files - one regarding the English Premier League stats for 2015-16 season and the other for 2016-17. Here is a snippet of the data from each file: { "name": "English Premier League 2015/16", "rounds": [ { "name": ...

Having trouble with expect().toThrow() function not functioning properly during test execution

I have written a test for a service in Angular4 that checks if an error is thrown when given an invalid Batch ID: it('should throw an error when given an invalid Batch ID', async(inject([EventLogService, HttpTestingController], (servic ...

Display the flowplayer div when the anchor is clicked

I have a dynamic CGI page that displays a list of files. The number of files varies based on uploaded content, so I am looking to create previews for video files. Below is a snippet of HTML code: <TMPL_LOOP files> <tr> <td&g ...

Moment.js is stating that there is no property called 'toISOString' on the type '{}'

I'm facing an issue with my code - the `value.toISOString()` function was working fine until now, but suddenly it's throwing a compiler error. I recently upgraded from Angular 7 to 8, which also bumped up the Typescript version to 3.4.5. Any sugg ...

Safari not rendering SVG wave at full width reached

My SVG isn't scaling to 100% width in Safari like it is in IE, Chrome, and Firefox. Despite numerous attempts, I haven't been able to make my SVG stretch across the full width like it does in other browsers. The project is built using React. . ...