If you are, for example, working on a chat application, one of the features that the user expects is an ability to send
a message with a keyboard shortcut. The example of a directive below shows how this can be achieved for Shift + Enter
combination:
1234567891011121314151617181920212223242526
.directive('sendMessage',function(){returnfunction(scope,element){varshiftDown=false;element.bind("keydown",function(event){// sets shiftDown to true if the shift key (key code is 16) is pressedif(event.which===16){shiftDown=true;}// sends the message if "enter" is pressed and "shift" is being held downif(event.which===13&&shiftDown){event.preventDefault();scope.send();scope.$apply();}});// sets shiftDown to false if the shift key has been releasedelement.bind("keyup",function(event){if(event.which===16){shiftDown=false;}});};});
You can play with a simple chat app that uses this directive on CodePen,
and fork the app on GitHub.
If you're looking for a developer or considering starting a new project,
we are always ready to help!