How can you disable the submit button when the form has errors in this template-driven forms example?

<form #userForm=”ngForm”>
    <input type=”text” ngModel name=”firstName” required>
    <input type=”text” ngModel name=”lastName” required>
    <button (click)=”submit(userForm.value)”>Save</button>
</form>
  • [ ] <button (click)=”submit(userForm.value)” disable=”userForm.invalid”>
    Save
</button>
  • [x] <button (click)=”submit(userForm.value)” [disabled]=”userForm.invalid”>
    Save
</button>
  • [ ] <button (click)=”submit(userForm.value)” [ngForm.disabled]=”userForm.valid”>
    Save
</button>
  • [ ] <button (click)=”submit(userForm.value)” *ngIf=”userForm.valid”>
    Save
</button>

Leave a Reply

Your email address will not be published. Required fields are marked *