1

I have a issue while using Angular reactive forms.

Please check this forked Stackblitz example from official Angular reactive forms docs, name editor form. In this example form has only one input control. I am using ngSubmit on <form> element and <button> is type="submit".

But when I submit form the page reloads. The default submit behaviour is not prevented.

CodeAndCode
  • 69
  • 1
  • 7

1 Answers1

2

(ngSubmit) must be used with [ngForm] else the submit button will trigger the standard HMTL submit.

This means you'll have to create a FormGroup for your FormControl.

Matthieu Riegler
  • 31,918
  • 20
  • 95
  • 134
  • that makes sense. I guess that I could use type button and add click to submit form, and remove ngSubmit. What do you think about that approach? – CodeAndCode Jan 23 '23 at 10:12