This is a very crude and probably buggy clone of Angular UI Keypress with Mousetrap under the hood.
JavaScript:
angular.module('myApp', ['mousetrap']);
...
// Note - it should support any kind of binding that mousetrap supports
$scope.test = {
'a': function() { console.log('"a" key was pressed'); },
'b': function() { console.log('"b" key was pressed'); }
}
HTML:
<span mousetrap-keypress="test">Press 'a' or 'b'</span>
Global bindings require Global Binding plugin.
Example usage of global bindings:
$scope.myKeybindings = {
bindGlobal: {
'ctrl+s': $scope.saveAction,
'command+s': $scope.saveAction
}
'ctrl+b': $scope.backAction
};
- AngularJS v1.0.2+
- Mousetrap v1.4.4+