要将Angular Material Stepper中的所有步骤设置为“非活动”,可以使用MatStepper
组件的selectedIndex
属性来实现。以下是一个示例代码:
在HTML模板中,设置一个按钮来触发将所有步骤设置为“非活动”的函数:
Step 1 content
Step 2 content
Step 3 content
在组件的JavaScript/TypeScript代码中,实现将所有步骤设置为“非活动”的函数:
import { Component, ViewChild } from '@angular/core';
import { MatStepper } from '@angular/material/stepper';
@Component({
selector: 'app-example',
templateUrl: './example.component.html',
styleUrls: ['./example.component.css']
})
export class ExampleComponent {
@ViewChild('stepper') stepper: MatStepper;
disableAllSteps() {
this.stepper.selectedIndex = -1;
}
}
在上述代码中,我们使用ViewChild
装饰器来获取到MatStepper
组件的实例。然后,在disableAllSteps
函数中,将selectedIndex
属性设置为-1,即将所有步骤设置为“非活动”。
当点击“Disable all steps”按钮时,所有步骤将变为非活动状态。