VOOZH about

URL: https://www.geeksforgeeks.org/angular-js/how-to-submit-form-on-pressing-enter-with-angular-9/

⇱ How to submit form on pressing Enter with Angular 9? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to submit form on pressing Enter with Angular 9?

Last Updated : 5 Nov, 2020

To submit a form in angular we have the following options:

  1. Create a button to submit the form.
  2. Assign a key to submit the form
  3. 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.

Approach:

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.

Example:

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:

Output:

👁 Image
Comment
Article Tags:

Explore