CodeAndCode
CodeAndCode

Reputation: 79

Angular Reactive Forms ngSubmit not working for single input control

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.

Upvotes: 1

Views: 527

Answers (1)

Matthieu Riegler
Matthieu Riegler

Reputation: 55072

(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.

Upvotes: 2

Related Questions