Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Angular form reloading the page?

I have the following forms, on the same page:

<form ng-submit="actionA()">
    <input type="text">
    <input type="submit" value="Submit">
</form>

<form ng-submit="actionB()">
    <input type="text">
    <input type="submit" value="Submit">
</form>

At the moment, when I submit either form, the page reloads. How do I prevent that? I know I could use event.preventDefault() but I'd like to know if there's a plain Angular solution.

like image 342
trs Avatar asked Apr 28 '26 21:04

trs


1 Answers

Make sure you import FormsModule from @angular/forms in the module containing your component because without it your form on submit will keep refreshing the page and failing silently without logging anything to the console.

like image 183
marwan abuassi Avatar answered Apr 30 '26 11:04

marwan abuassi