Last active
August 29, 2015 14:01
-
-
Save fisshy/6d61500cd226b3f12b32 to your computer and use it in GitHub Desktop.
Execute function when pressing enter
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
angular.module('moduleName') | |
.directive('ngEnter', function () { | |
return { | |
scope: { | |
ngEnter: '&' | |
}, | |
link: function ($scope, $element) { | |
$element.bind("keydown keypress", function (event) { | |
if (event.which === 13) { | |
$scope.ngEnter(); | |
event.preventDefault(); | |
} | |
}); | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment