简体   繁体   English

如何动态改变primeNG进度背景?

[英]How to dynamically change the primeNG progress background?

I'm working with the primeNG progress component and I would like to change the color of the progress bar depending on the value. 我正在使用primeNG进度组件 ,我想根据值更改进度栏的颜色。 So 25% 25% is blue and 75% is green. 因此25%25%是蓝色,而75%是绿色。

I've found that I can override the given color with: 我发现我可以使用以下方法覆盖给定的颜色:

.delay .progressBarDelay .ui-progressbar .ui-progressbar-value {
    background: red;
}

the HTML: HTML:

<div class="delay">
    <p>{{list.delay}}</p>                
    <div><p-progressBar class="progressBarDelay" [value]="list.value" [showValue]="false"></p-progressBar></div>
</div>

But now all the elements are red. 但是现在所有元素都是红色的。 And I have multiple progress bars. 我有多个进度条。 Is there a way to set the background color depending on the given value? 有没有一种方法可以根据给定的值设置背景色?

you can change class depending on value, it think so, something like this:- 您可以根据值更改类,它会这样认为:-

<p-progressBar [ngClass]="{'progressBar-green': list.value > 50, 'progresbar-red': list.value < 50}" [value]="list.value" [showValue]="false"></p-progressBar>

You can pass a function to ngClass where you can define your logic. 您可以将函数传递给ngClass,在其中您可以定义逻辑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM