I have a Angular 5 project where I’m using a material progress bar. I want to use custom colors. I’ve tried several workarounds (including previous SO questions) , but cannot break the code. I want to change the color based on percent progress. HTML:
<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>`
sass (css):
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 {
.mat-progress-bar-fill {
&::after {
background-color: $red;
}
}
}
&.color-yellow {
.mat-progress-bar-fill {
&::after {
background-color: $yellow;
}
}
}
&.color-green {
.mat-progress-bar-fill {
&::after {
background-color: $green;
}
}
}
&.color-aqua {
.mat-progress-bar-fill {
&::after {
background-color: $aqua;
}
}
}
}
}
}
Any help VERY much appreciated...:-)
Setting the color in .ts file worked for me
and in .ts file,
I believe you can replace 'primary' with your custom color
https://i.stack.imgur.com/P98jU.png