要为每个mat-horizontal-stepper的stepper图标设置不同的背景颜色,可以使用Angular Material提供的自定义stepper模板。以下是一个示例解决方案:
在HTML模板中,使用mat-step-header来自定义stepper头部的模板,并将背景颜色绑定到自定义属性中:
Step 1
Step 2
在组件的TS文件中,定义用于存储每个step的背景颜色的属性,并设置不同的颜色值:
import { Component } from '@angular/core';
@Component({
selector: 'app-stepper',
templateUrl: './stepper.component.html',
styleUrls: ['./stepper.component.css']
})
export class StepperComponent {
colorOne = 'red';
colorTwo = 'green';
}
在CSS文件中,为自定义的step-header样式添加样式:
.custom-step-header {
padding: 10px;
color: white;
}
这样就可以为每个mat-horizontal-stepper的stepper图标设置不同的背景颜色了。在组件的TS文件中,通过修改colorOne和colorTwo的值可以动态改变背景颜色。