Last active
August 29, 2015 14:02
-
-
Save billyxs/55a3be71b5c86d9d4e9a to your computer and use it in GitHub Desktop.
Angular - On Enter Keypress Directive
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
app.directive('xs-enter', function () { | |
return function (scope, element, attrs) { | |
element.bind("keydown keypress", function (event) { | |
event.preventDefault(); | |
if(event.which === 13) { | |
scope.$apply(function (){ | |
scope.$eval(attrs.xsEnter); | |
}); | |
} | |
}); | |
}; | |
}); |
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
<input type="text" data-xs-enter="yourEvent()"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment