I'm using the directive from this answer to run a function when the enter key is pressed in an input field.
How can I pass the value of the input field element.val()
to the function the directive calls? Or pass the input field element
to the function, to clear the value after it's retrieved.
HTML
<input type="text" ng-enter="newField()" />
JS
app.directive('ngEnter', function() {
return function(scope, element, attrs) {
element.bind("keydown keypress", function(event) {
if(event.which === 13) {
element.val(); // value of input field
scope.$apply(function(){
scope.$eval(attrs.ngEnter); // passed to this function
});
event.preventDefault();
}
});
};
});