I am trying to detect the enter key event when on a form submit, The enter key event works only if there any value present in any of the form components.
But the enter key event is not working in the case of the empty form (ie no value present in any of the form elements)
<form (keydown)="keyDownFunction($event)">
<input type="text" />
</form>
Ts file
keyDownFunction(event) {
if (event.keyCode === 13) {
alert("you just pressed the enter key");
// rest of your code
}
}
Here is the stackbliz URL https://stackblitz.com/edit/angular-7v744e