【问题标题】:Angular mat-step change icon color角度垫步更改图标颜色
【发布时间】:2020-08-03 06:55:08
【问题描述】:

我需要根据我的数组属性更改垫步图标(角度材料步进器)的背景颜色:etape.etat。

    <div *ngFor="let etape of pro.etapes; let i=index">

      <mat-step *ngIf="etape.etat == 1" style="background-color: yellow;">
        <ng-template matStepLabel> {{ etape.nomEtape }} </ng-template>
      </mat-step>

      <mat-step *ngIf="etape.etat ==2" style="background-color: green;">
        <ng-template matStepLabel> {{ etape.nomEtape }} </ng-template>

      </mat-step>

      <mat-step *ngIf="etape.etat ==2" style="background-color: red;">
        <ng-template matStepLabel> {{ etape.nomEtape }} </ng-template>

      </mat-step>

    </div>
    </mat-horizontal-stepper>

但是,背景颜色只能使用 :

::ng-deep .mat-step-header .mat-step-icon{
  background-color: red; 
}

是否有可能根据条件动态更改垫步图标颜色?

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    HTML 中:使用 [ngClass] 并将条件设置为 classYellowclassGreenclassRed

    TS 中:操作进入 HTML 条件的变量

    CSS 内部:从您放置 ngClass 的位置遍历到 mat-step-icon 以设置背景颜色...类似于:

    ::ng-deep .classYellow. mat-step-header .mat-step-icon{
      background-color: yellow; 
    }
    

    样本stackblitz here

    【讨论】:

    • 感谢您的回复。但是,条件取决于 for 循环。我不能把它放在垫子水平步进器中。我需要将它插入到垫步中。
    • @ghada 也在找同样的事情,你找到解决办法了吗?
    猜你喜欢
    • 2019-07-27
    • 2018-09-23
    • 1970-01-01
    • 2019-07-01
    • 1970-01-01
    • 2020-07-04
    • 2020-01-21
    • 1970-01-01
    • 2021-01-29
    相关资源
    最近更新 更多