角 4 &材料步进器 [英] Angular 4 & Material Stepper
本文介绍了角 4 &材料步进器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 步进器内部重置(或只是跳到第一步)
Is it possible to reset (or just jump to the first step) inside of a stepper? It is not documented in the docs, but is it possible to do so? It is stated in the docs that the stepper is built on "CDK Stepper" (link?), but I can't find any examples which lead me to my goal.
推荐答案
好的,我似乎找到了一个解决方案(但 API 上没有说明).
Ok, it seems I found a solution (but it is not stated anywhere on the API).
- 添加对步进器的引用,然后在组件打字稿文件中添加带有引用的
ViewChild
. - 创建一个方法来更改步进器的索引.
HTML:
<mat-horizontal-stepper [linear]="true" #stepper>
<!-- Content here -->
</mat-horizontal-stepper>
TS:
import { Component, ViewChild } from '@angular/core';
@Component({
// ...
})
export class AppComponent {
@ViewChild('stepper') stepper;
/**
* Changes the step to the index specified
* @param {number} index The index of the step
*/
changeStep(index: number) {
this.stepper.selectedIndex = index;
}
}
这篇关于角 4 &材料步进器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文