If I submit a form using
button type="submit" the form validation messages appear and everything is fine. However if I have a button (or link) with
(click)="myhandler()" then the validations do not appear.
How can I either:
- tag the element as requiring validators to run, or
- programatically run and show validation messages.
Note: These are simple validations like required on input fields.
<form (ngSubmit)="save()"> <input required type='text' [(ngModel)]="name"> <!-- Shows validation messages but still calls save() --> <button (click)="save()">Click</button> <!-- Only submits if valid and shows messages --> <button type="submit">Submit</button> </form> <!-- does not even show validation messages, just calls save --> <button (click)="save()">Click 2</button>