我正在try 使用PrimeNG中的p-Steps组件.我想对已完成和未完成的步骤有不同的造型.也就是说,如果用户当前处于第3步,则第1步和第2步已完成,我想将背景 colored颜色 设置为绿色. 我注意到PrimeNG 14不再支持p-Steps-Complete.

我的组件实现非常基本:

<p-steps
  #stepModule
  [model]="items"
  [readonly]="false"
  [activeIndex]="stepEvent.stepIndex">
</p-steps>

谢谢

推荐答案

由于PrimeNG 14不再支持p-Steps-Complete,因此唯一的机会就是使用CSS

想象一下在style中.css类似于

.p-steps.completed-1 .p-steps-item:nth-child(-n + 1) .p-menuitem-link .p-steps-number,
.p-steps.completed-2 .p-steps-item:nth-child(-n + 2) .p-menuitem-link .p-steps-number,
.p-steps.completed-3 .p-steps-item:nth-child(-n + 3) .p-menuitem-link .p-steps-number,
.p-steps.completed-4 .p-steps-item:nth-child(-n + 4) .p-menuitem-link .p-steps-number
{
  background:red;
  color:white;
  border: 1px solid crimson;
}

通过这种方式,您可以"完成"一个变量

completed=0;

你的p步骤用了styleClass

<p-steps [model]="items" 
         [(activeIndex)]="activeIndex" 
         [readonly]="false" 
         [styleClass]="'completed-'+completed">
</p-steps>

因此,当您将变量"Complete"更改为1、2、3或4时,您会看到应用的样式

stackblitz

Updated如果我们想要"活动"而不是得到 colored颜色 ,我们可以使用:not(.p-highlight)

.p-steps.completed-1 .p-steps-item:nth-child(-n + 1):not(.p-highlight) .p-menuitem-link .p-steps-number,
.p-steps.completed-2 .p-steps-item:nth-child(-n + 2):not(.p-highlight) .p-menuitem-link .p-steps-number,
.p-steps.completed-3 .p-steps-item:nth-child(-n + 3):not(.p-highlight) .p-menuitem-link .p-steps-number,
.p-steps.completed-4 .p-steps-item:nth-child(-n + 4):not(.p-highlight) .p-menuitem-link .p-steps-number
{
  background:red;
  color:white;
  border: 1px solid crimson;
}

Angular相关问答推荐

根据Angular中的构建来卸载独立组件

接收错误NullInjectorError:R3InjectorError(_AppModule)[config—config]....>过度安装Angular—Markdown—Editor

元件不工作时的Angular 17属性 Select 器

[已解决]如何在模块ngDoBootstrap中测试Angular 自定义元素和做覆盖

在Drective Composure API中使用指令输出

如何使用来自不同可观测对象的值更新可观测对象

如何使用Angular 将图像作为二进制数据发送到我的API?

MonoTypeOperatorFunction不可分配给OperatorFunction类型的参数

NG-Zorro Datepicker 手动输入掩码不起作用

区分material 手风琴

过滤 ngfor Angular 的计数

可从 Angular2 中的

如何在 Angular4 中访问组件的 nativeElement?

如何在 Angular 2 中获取与 ElementRef 关联的组件的引用

如何在Angular 4中为数字管道指定语言环境千位分隔符

NgrxStore 和 Angular - 大量使用异步管道或在构造函数中只订阅一次

Angular 2 setinterval() 继续在其他组件上运行

如何使用 CLI 创建特定版本的 Angular 项目?

在 Angular 2 中使用 store (ngrx) 有什么好处

如何在Angular中使用带有 td 属性 colspan 的属性绑定?