In order to submit a form in Angular 2 we can either use form's "submit" or "ngSubmit" event.
<form #frm="ngForm" (submit)="add(frm.value)"> ... </form> <form #frm="ngForm" (ngSubmit)="add(frm.value)"> ... </form>
Would like to know whats the difference between the two ?
from this tutorial, https://blog.thoughtram.io/angular/2016/03/21/template-driven-forms-in-angular-2.html
However, ngSubmit ensures that the form doesn’t submit when the handler code throws (which is the default behaviour of submit) and causes an actual http post request. Let’s use ngSubmit instead as this is the best practice:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With