3

I am working on an Angular2 project wherein I want to incorporate Shortcut keys for various functionalities.

I am confused between two approaches. One is to create shortcuts by using HostListener as below :

@HostListener('document:keydown', ['$event'])
  handleHotkey(event: KeyboardEvent){
  ... 
}

The other approach is to use Mousetrap JS framework and then create a service around it which is customized to my project as done in angular2-hotkeys.

Some Pros according to me of using Mousetrap over Hostlistener -

  1. A common service to add/remove/pause/unpause shortcuts.
  2. Reading of hotkeys from a config file.
  3. Ease of coding and maintenance.

Which would be a better approach for angular2.

I am especially concerned about degraded performance.

harsrawa
  • 422
  • 5
  • 18

0 Answers0