#multiple keydown binding in template vs all in typesript file

1 messages · Page 1 of 1 (latest)

glad shoal
#

What do you prefer to use and why:
all done in template:

<input 
  (keydown.enter)="submitValue()"
  (keydown.escape)="resetValue()"
  (click)="handleClick()"
>

or use multiple HostBinding in typescript file? Or something else maybe?

shrewd shell
#

HostBinding is used to define event bindings on the host element of the component. Not on a specific input of the template of the component.
What you have there is reasonable, except the enter binding shouldn't be necessary (it's the browser default behavior to submit the form when enter is pressed in one of its inputs).

glad shoal
#

We actually don't use form tags. We have FormControls that we bind to input fields.
Then we have submitHandler on a button that sets various states on formRoot instance. And if all good, then we send request to backend. I gues reason is that other components talk to formRoot instance and for example display list with errors.