What is AngularJS way to create global keyboard shortcuts?

后端 未结 12 2114
一整个雨季
一整个雨季 2020-11-30 22:04

I suppose that I should use directive, but it seems strange to add directive to body, but listen events on document.

What is a proper way to do this?

UPDATE:

12条回答
  •  离开以前
    2020-11-30 22:45

    I can't vouch for it just yet but I've started taking a look at AngularHotkeys.js:

    http://chieffancypants.github.io/angular-hotkeys/

    Will update with more info once I've got my teeth into it.

    Update 1: Oh there's a nuget package: angular-hotkeys

    Update 2: actually very easy to use, just set up your binding either in your route or as I'm doing, in your controller:

    hotkeys.add('n', 'Create a new Category', $scope.showCreateView);
    hotkeys.add('e', 'Edit the selected Category', $scope.showEditView);
    hotkeys.add('d', 'Delete the selected Category', $scope.remove);
    

提交回复
热议问题