I have a angular material linear stepper
each step is a separate angular component
containing a form
which needs validation
The validation simply just isn't working. I can progress through to the next step without completing the form.
To illustrate what I mean I have created a condensed version on stackblitz.
The main things to look at (I think) is the 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>
And each step-X-component
Here is the stackblitz. https://stackblitz.com/edit/angular-vpoj5j
Your stepper and forms components works on different form objects. You need to set super's forms objects in step component's
ngONInit()
instead
The problem is in your CreateProfileComponent:
There is no relation between your defined FormGroup's in CreateProfileComponent and your stepper components. You tried to extend every StepComponent with CreateProfileComponent, but with this approach every StepComponent holds his own instance of CreateProfileComponent and so there own FormGroup's declaration.
To solve your problem you can declare template variables for every StepComponent in your html (starting with #) and pass the formControl to [stepControl]:
Or you leave your html as it is and work with ViewChild() (My preferred approach).
Either way there is no need to extend your StepComponents with CreateProfileComponent and it doesn't make any sense.