In Angular, how I add button without submit the form?
for example I want to call onCancel
without submit the form, but update button should be submit the form, and still keep the ngSubmit
.
<form [formGroup]="form" (ngSubmit)="submit()">
<p>
<select ...>...</select>
</p>
<p>
<button
type="submit"
mat-raised-button
color="primary">
update
</button>
<button mat-raised-button (click)="onCancel($event)">
cancel
</button>
</p>
</form>
Just add type='button'
to it. A button without any defined type
in a form acts like a submit
button for the form.