In this case I would recommend that you create a custom directive for the mat-progress-spinner element.
Here's how I solved your problem using custom directives:
- Create a new directive in Angular by running the following command:
ng g d spinner-variable-color
- I updated the directive so it looked like this (you can refactor/simplify the code but I just did this fast to see if it works):
import { Directive, ElementRef, Input } from '@angular/core';
@Directive({
selector: '[spinnerVariableColor]'
})
export class SpinnerVariableColorDirective {
constructor(
private elem: ElementRef
){}
ngAfterViewInit(){
const element = this.elem.nativeElement;
const progress = element.getAttribute('aria-valuenow');
const circle = element.querySelector('circle');
if (progress > 20) {
circle.style.stroke = '#6aa1fe';
} else {
circle.style.stroke = 'black';
}
}
}
- You can now use it in your component like this:
<mat-progress-spinner spinnerVariableColor [value]="progress"></mat-progress-spinner>
where progress is just a variable I created to keep track of progress.
Hope this helped you solve your problem :)
If you want to know more about custom directives in Angular I have a great article about it on my website -> What Is Custom Directives In Angular