how to prevent onSubmit() function getting called on click of a cancel button
Put type="button"
explicitly to avoid button trigerring a form submission
<button mat-button type="button" (click)="onNoClick()">Cancel</button>
You can check the spec here Note that the default behaviour is submit
unless specified otherwise.