In an Angular 11 project I have an Angular Material Stepper control. My first step contains a form much like this:
<mat-horizontal-stepper [linear]="true" #stepper>
<mat-step [stepControl]="step.formGroup">
<form [formGroup]="formGroup">
<label for="code">Enter code</label>
<input name="code" formControlName="code" required />
<button matStepperNext>Continue</button>
</form>
</mat-step>
<mat-step>
<!-- step 2 -->
</mat-step>
</mat-horizontal-stepper>
I would like to show the <button>
that's decorated with matStepperNext
as disabled when the form has errors and enabled when it doesn't using CSS classes. How can I get this done?
CSS of the button:
I would still suggest to handle it using
disabled
attribute on the button.