How to submit form on pressing Enter with Angular 9?
To submit a form in angular we have the following options:
- Create a button to submit the form.
- Assign a key to submit the form
- Or we can do both.
In this tutorial, we will see how to use a specific key(Enter in this case) to submit a form.
We can use angular keydown event to use Enter key as our submit key.
- Add keydown directive inside the form tag.
- Create a function to submit the form as soon as Enter is pressed.
- Assign the keydown event to the function.
Let’s create a form having both, button and Enter key as mode of form submission.
- We will use bootstrap classes, so add bootstrap scripts in your index.html.
- code for the component:
My Personal Notes arrow_drop_up
Please Login to comment...