You can use the completed property of mat stepper to restrict the next button if any of the field is invalid.
<mat-horizontal-stepper [linear]="true">
<mat-step label="Form-1" [completed]="appForm1?.isCompleted ? true : false">
<app-form1></app-form1>
</mat-step>
<mat-step label="Form-2" [completed]="appForm2?.isCompleted ? true : false">
<app-form2></app-form2>
</mat-step>
<mat-step label="Form-3" [completed]="appForm3?.isCompleted ? true : false">
<app-form3></app-form3>
</mat-step>
</mat-horizontal-stepper>
In your parent.ts component you need to add child component references.
@ViewChild(AppForm1Component) public appForm1: AppForm1Component;
@ViewChild(AppForm2Component) public appForm2: AppForm2Component;
@ViewChild(AppForm3Component) public appForm3: AppForm3Component;
And in your each component you can add get property isCompleted which will return validation and other check whatever you want to add for NEXT button. Like in your AppForm1Component.ts:
get isCompleted(): boolean {
return (this.form.valid && other checks)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…