简体   繁体   English

如何在ng-zorro中更改进度圆圈的笔触颜色?

[英]How can i change the stroke color of the progress circle in ng-zorro?

In my Angular project I have a dashboard in mind, which shows me different process circles. 在我的Angular项目中,我想到了一个仪表板,该仪表板向我展示了不同的过程界。 Depending on the progress I want to change the color of the line. 根据进度,我想更改线条的颜色。

This is what it looks like right now. 这就是现在的样子。 看起来如何 This is how it should look like. 这就是它的外观。 它应该看起来如何

Unfortunately I cannot change the color with eg [nzStrokeColor]="'red'". 不幸的是,我无法使用[nzStrokeColor] =“'red'”更改颜色。

<div class="flex">
  <nz-card class="cards" *ngFor="let card of dashboarcard">
    <nz-card-meta [nzAvatar]="avatarTemplate" [nzTitle]="card.titel" nzDescription="12.01.2019"> </nz-card-meta>
    <ng-template #avatarTemplate>
      <nz-progress [nzStrokeColor]="'red'" [nzWidth]="40" nzType="circle" [nzPercent]="card.percent"></nz-progress>
    </ng-template>
  </nz-card>
</div>

Right now it's always blue, no matter what I enter. 不管我输入什么,现在总是蓝色。
Do you have any idea what I'm doing wrong? 你知道我在做什么错吗?

Many greetings, 许多问候,
Jin

With ng-zorro-antd@1.8.1 you can't change stroke attribute for svg:path.ant-progress-circle-path since it was added only in 7.0.0-rc.0 使用ng-zorro-antd@1.8.1您无法更改svg:path.ant-progress-circle-path stroke属性,因为它仅添加在7.0.0-rc.0中

So I updated your Stackblitz and It actually works as intended: 所以我更新了您的Stackblitz ,它实际上按预期工作:

在此处输入图片说明

You can see it changes stroke attribute to red BUT 您可以看到它将stroke属性更改为red

SVG presentation attributes have lower priority than other CSS style rules specified in author style sheets or 'style' attributes . SVG表示属性的优先级低于作者样式表或'style'属性中指定的其他CSS样式规则

That means that stroke="red" will be overrided by .ant-progress-circle-path class and that's what we see in the picture above. 这意味着stroke="red"将被.ant-progress-circle-path类覆盖,这就是我们在上图中看到的内容。

So that the only one way to override it is to override that class. 因此,覆盖它的唯一方法是覆盖该类。


Here are several ways of how it can be accomplish: 这里有几种方法可以实现它:

1) Add override to your global styles ( stackblitz ) 1)添加覆盖到您的全局样式( stackblitz

styles.css styles.css的

path.ant-progress-circle-path { stroke:red }

Note: we added element to class so it will have higher specificity that just class so we do not need !important here 注意:我们在类中添加了元素,因此它比类具有更高的特异性,因此我们不需要!important

2) Use ::ng-deep combinator in `app.component.css ( stackblitz ) 2)在app.component.css( stackblitz )中使用::ng-deep组合器

app.component.css app.component.css

::ng-deep .ant-progress-circle-path { stroke:red;}

3) Add the same rule to app.component.css presetting encapsulation to ViewEncapsulation.None for component ( stackblitz ) 3)向app.component.css添加相同的规则以encapsulation ViewEncapsulation.NoneViewEncapsulation.None组件( stackblitz

app.component.ts app.component.ts

@Component({
  ...
  encapsulation: ViewEncapsulation.None
})
export class AppComponent  {

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

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