An attribute directive to listen to keydown events
An easy synthax to bind yourself to the keydown event.
Use this page to know the correspondance between key and code.
mappings : the functions to call when the keys are pressed, see usage section for synthax
<input ng-model="myValue" class="lui input" luid-keydown mappings="myMappings">
var enterPressed = function(){ ... };
var escPressed = function(){ ... };
$scope.myMappings = { 13: enterPressed, 27: escPressed, keyCode: fun };
If in the function called you change a variable in the $scope, you have to call $scope.$apply(); yourself for this modification to take effect.
$scope.enterCnt = 0;
var enterPressed = function(){
$scope.enterCnt++;
$scope.$apply();
};
$scope.myMappings = { 13: enterPressed };
Will count the number of times keys enter, esc and the letter z are pressed,
will also listen to arrow keys and append an array.
{{enterCnt}} keydown of key enter{{escCnt}} keydown of key esc{{zCnt}} keydown of key z{{arrows.join(" ")}}