Daniel Que
Daniel Que

Reputation: 1734

Adding multiple hotkeys to an element with AngularJS?

I'm currently using Angular UI to add a hotkey to an element, but it doesn't seem to support multiple hotkeys. What would be the best way to get this working?

Upvotes: 0

Views: 415

Answers (1)

Preview
Preview

Reputation: 35846

Not using Angular-UI, but you maybe you could have a look to the angular-hotkeys directive, it allow you to bind one or more keys to an event function.

Example

<div hotkey="{ 'A': functionA, 'B': functionB }"></div>

$scope.functionA = function (event) {
    event.preventDefault();
    console.log('A key pressed.');
}

$scope.functionB = function (event) {
    event.preventDefault();
    console.log('B key pressed.');
}

Upvotes: 1

Related Questions