角度4和物料步进 [英] Angular 4 & Material Stepper
本文介绍了角度4和物料步进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在步进器内进行重置(或仅跳至第一步)一个>? 它没有记录在文档中,但是有可能这样做吗? 在文档中指出,步进器基于"CDK步进器"(
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
及其引用. - 创建一种方法来更改步进器的索引.
- Add a reference to the stepper, then add
ViewChild
with the reference in your component typescript file. - Create a method to change the index of the stepper.
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屋!
查看全文