you probably need to access ratingValue.value to get the current value of the formControl.
Then use ngClass like you did in your example:
[ngClass]="{'black':ratingValue==0,'red':ratingValue==1,'blue':ratingValue==2,'yellow':ratingValue==3,'pink':ratingValue==4,'green':ratingValue==5}">
or even better (looks cleaner) pass a function to the ts file:
[ngClass]="getStarColorCSSClass(ratingValue.value)"
and in the TS file:
getStarColorCSSClass(value: number): string {
switch(value) {
case 0:
return 'black';
case 1:
return 'red';
case 2:
return 'blue';
case 3:
return 'yellow'
case 4:
return 'pink';
default:
return 'green';
}
}
}
If your CSS classes are only created for setting the 'color' property,
we can also avoid to create them by using ngStyle instead of ngClass (with the function above):
[ngStyle]="{color: getStarColorCSSClass(ratingValue.value)}"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…