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 directive 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:
- How to disable form submit on enter button using jQuery ?
- How to submit a form on Enter button using jQuery ?
- Routing in Angular JS using Angular UI Router
- Angular CLI | Angular Project Setup
- Angular 7 | Angular Data Services using Observable
- Adding Angular Material Component to Angular Application
- Difference between Angular 4 and Angular 5
- HTML | DOM Input Submit form Property
- HTML | DOM Form submit() Method
- How to create a PHP form that submit to self ?
- How to detect “shift+enter” and generate a new line in Textarea?
- 13 Things You Should Know Before You Enter In Web Development
- D3.js selection.enter() Function
- How to clear form after submission in Angular 2?
- HTML | DOM Input Submit formTarget Property
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.