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 create a PHP form that submit to self ?
- HTML | DOM Form submit() Method
- HTML | DOM Input Submit form Property
- How to clear form after submission in Angular 2?
- Adding Angular Material Component to Angular Application
- Angular 7 | Angular Data Services using Observable
- Routing in Angular JS using Angular UI Router
- Angular CLI | Angular Project Setup
- Difference between Angular 4 and Angular 5
- 13 Things You Should Know Before You Enter In Web Development
- How to detect “shift+enter” and generate a new line in Textarea?
- AngularJS | ng-submit Directive
- jQuery | submit() with Examples
- jQuery | :submit Selector
- HTML | <input type="submit">
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.