Skip to content

Instantly share code, notes, and snippets.

@adickson311
Last active August 29, 2015 14:21
Show Gist options
  • Save adickson311/7cd33a9748502097d041 to your computer and use it in GitHub Desktop.
Save adickson311/7cd33a9748502097d041 to your computer and use it in GitHub Desktop.
Angular - Watch for key press on multiple form elements
// Route multiple form elements to a single method to handle key presses in Angular
//ng-keypress="checkKey($event)"
$scope.checkKey = function(e){
if(e.charCode === 13){ // 13 = Enter
switch(e.currentTarget.name){
case 'elementName':
$scope.doThing();
break;
case 'elementTwo':
var item = angular.element(e.currentTarget).scope().item;
doOtherThing(item);
break;
}
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment