我有一个angular material linear stepper,每个步骤都是一个单独的angular component,其中包含一个需要validation的form
验证根本就不起作用。我可以在不填写表单的情况下继续下一步。
为了说明我的意思,我在stackblitz上创建了一个压缩版本。
(我认为)要查看的主要内容是create-profile.component.html
<mat-horizontal-stepper linear #stepper>
<mat-step [stepControl]="frmStepOne">
<ng-template matStepLabel>Step One Details</ng-template>
<step-one-component></step-one-component>
</mat-step>
<mat-step [stepControl]="frmStepTwo">
<ng-template matStepLabel>Step Two Details</ng-template>
<step-two-component></step-two-component>
</mat-step>
<mat-step [stepControl]="frmStepThree">
<ng-template matStepLabel>Step Three Details</ng-template>
<step-three-component></step-three-component>
</mat-step>
</mat-horizontal-stepper>和每个step-X-component
这就是stackblitz。https://stackblitz.com/edit/angular-vpoj5j
发布于 2021-01-08 16:58:49
要使每个步骤都作为其自己的组件的mat-stepper,请创建按钮以遍历组件外部的stepper,并基于在单个组件内完成的表单验证显示/隐藏遍历按钮,并将表单信息公开给父stepper。
例如:
<mat-horizontal-stepper #stepper linear iseditable>
<mat-step
[stepControl]="firstFormGroup"
[completed]="primaryIsTrue"
>
<app-primary-settings
(formIsValid)="formValidity($event)"></app-primary-settings>
<button mat-button matStepperNext
*ngIf="primaryIsTrue">
Next
</button>
</mat-step>
</mat-horizontal-stepper>https://stackoverflow.com/questions/48498966
复制相似问题