var myApp = angular.module('myApp', []);
myApp.directive('enterDirective', function () {
return {
link: function (scope, element, attrs) {
$(element).keypress(function (e) {
if (e.keyCode == 13) {
console.log("Enter pressed " + element.val())
}
});
}
}
});
//myApp.factory('myService', function() {});
myApp.controller('MyCtrl', function ($scope) {
$scope.action = function () {
//notice how this is clicked when you hit the enter key
console.log("button clicked");
};
})
<div ng-controller="MyCtrl">
<form>
<input type="text" class="edit-input" enter-directive />
<button ng-click="action()">Perform action</button>
</form>
</div>
External resources loaded into this fiddle: