The HTML form element has an onSubmit event handler. Every time the submit button is clicked or the Enter key is pressed, the handler function is invoked. By default, the browser will refresh the page when a form submission event is triggered.
Use the preventDefault()
method on the event object to prevent a page refresh on form submit.
Code snippet for component.html.
<form (submit)="onSubmit($event)">
<input (input)="onInput($event)" />
</form>
Code snippet for component.ts.
onSubmit(e: Event) {
e.preventDefault();
}