Last active
August 29, 2015 14:21
-
-
Save adickson311/7cd33a9748502097d041 to your computer and use it in GitHub Desktop.
Angular - Watch for key press on multiple form elements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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