如何解决步进材料:在打字稿中使用 stepper.reset()
是否可以在 ts 文件中使用 stepper.reset()?我想做类似的事情
onCheckRef() {
if (this.refFormGroup.get('reference').invalid) {
this.stepper.reset();
} else {
.....................
}
}
在模板中:
<button mat-button (click)="onCheckRef()" matStepperNext>Valider</button>
谢谢
解决方法
是的,您可以使用 ViewChild 装饰器访问组件内部的 MatStepper Reference
首先在html中使用hash sympol定义模板引用变量
<mat-horizontal-stepper [linear]="isLinear" #stepper>
.....
</mat-horizontal-stepper>
然后在组件内部使用ViewChild装饰器访问步进器实例
@ViewChild('stepper',{read:MatStepper}) stepper:MatStepper;
终于可以访问reset方法了
onCheckRef() {
if (this.refFormGroup.get('reference').invalid) {
this.stepper.reset();
} else {
.....................
}
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。