垫步进机组件中的每一步

编程入门 行业动态 更新时间:2024-10-24 04:44:28
本文介绍了垫步进机组件中的每一步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想实现一个垫式步进器,每个步骤都在不同的组件中,我的问题是如果该步骤未完成,则要防止单击下一步按钮:

I would like to implement a mat-stepper, every step is in a different component, my problem is to prevent the next button is clicked if the step is not completed:

parent.html: <mat-horizontal-stepper> <mat-step [stepControl]="stepOneForm [completed]="stepOneForm?.valid"> <ng-template matStepLabel>Step1</ng-template> <child-step-1 [stepOne]="stepOneForm" (stepOneEmitter)="updateStepOne($event)"> </child-step-1 > </mat-step> <mat-step [stepControl]="stepTwoForm [completed]="stepTwoForm?.valid"> <ng-template matStepLabel>Step2/ng-template> <child-step-2 [stepTwo]="stepTwoForm" (stepTwoEmitter)="updateStepTwo($event)"> </child-step-2 > </mat-step> </mat-horizontal-stepper> parent.ts: stepOneForm: FormGroup; stepTwoForm: FormGroup; ////////// updateStepOne(step: FormGroup) { this.stepOneForm = step; } updateStepTwo(step: FormGroup) { this.stepTwoForm = step; } child-1.html <form [formGroup]="stepOne" (change)="updateStepOne()"> <mat-form-field> <input matInput required type="text" formControlName="title"/> </mat-form-field> <button mat-button matStepperNext><mat-icon>arrow_forward</mat-icon></button> </form> child-1.ts this.stepOne = this.fb.group({ title: ['Default title', [ Validators.required ]] }); updateStepOne() { this.stepOneEmitter.emit(this.stepOne); }

一切正常,但stepControl仍然有效,即使表单无效也可以进行下一步.

Everything works but the stepControl, it is possible to go to next step even when the form is not valid.

我的错误在哪里?

推荐答案

您正在同时使用 [stepControl] 和 [completed] .在这种情况下, stepControl 将被解释为比 [completed] 更重要.如官方文档中所述:

You are using [stepControl] and [completed] at the same time. In this case stepControl is going to be interpreted as more important as [completed]. As stated in official documentation:

或者,如果您不想使用Angular表单,则可以将completed属性传递到每个步骤,直到用户将其变为true为止,否则该步骤将不允许用户继续.请注意,如果同时设置了complete和stepControl,则将优先使用stepControl.

Alternatively, if you don't want to use the Angular forms, you can pass in the completed property to each of the steps which won't allow the user to continue until it becomes true. Note that if both completed and stepControl are set, the stepControl will take precedence.

这里是链接> material.angular.io/components/stepper/概述

更多推荐

垫步进机组件中的每一步

本文发布于:2023-11-26 21:20:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635234.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:步进   机组

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!