Skip to content

Instantly share code, notes, and snippets.

@rehrumesh
Created August 12, 2016 15:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rehrumesh/019ed540e305f9749dbda889adf5b1f6 to your computer and use it in GitHub Desktop.
Save rehrumesh/019ed540e305f9749dbda889adf5b1f6 to your computer and use it in GitHub Desktop.
(function (module) {
'use strict';
module.directive('ngEnter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if(event.which === 13) {
scope.$apply(function (){
scope.$eval(attrs.ngEnter);
});
event.preventDefault();
}
});
};
});
})(angular.module('common'));
// Usage
// <input ng-model="model" ng-enter="func()" />
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment