<mat-horizontal-stepper [linear]="isLinear" #stepper>
<!-- Your other steps here -->
<mat-step [stepControl]="secondFormGroup">
<!-- Content in the step -->
<div>
<!-- Other actions here -->
<button mat-button (click)="resetStepper(stepper)">Reset</button>
</div>
</mat-step>
<!-- More steps here -->
</mat-horizontal-stepper>
TypeError: Cannot read property 'toArray' of undefined
at MdVerticalStepper.webpackJsonp.../../../cdk/esm5/stepper.es5.js.CdkStepper._anyControlsInvalid (stepper.es5.js:351)
<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;
}
}
3 回答
In your template:
在步进器中添加ID,例如 #stepper . 然后在步骤中添加一个按钮,并在 (click) 上的函数中传递步进器ID,如下所示:
.. and in your typescript:
Stackblitz demo
我尝试了提供的解决方案,他们几乎为我工作,我得到以下错误:
这个小调整对我有用(使用Material 2 beta 11):
好吧,似乎我找到了一个解决方案(但它没有在API的任何地方说明) .
添加对步进器的引用,然后在组件打字稿文件中添加带引用的
ViewChild
.创建一个方法来更改步进器的索引 .
HTML:
TS: