I have a directive that, when enter is pressed, an event or expression is fired. I want to pass the element value to the event or expression as seen by my attempt: { 'myArg': element.val() }
The directive works and my event is called, but the parameter is undefined.
What am I missing or what do I need to fix?
app.directive('schdKeyenter', function () {
return function (scope, element, attrs) {
element.bind("keydown keypress", function (event) {
if (event.which === 13) {
scope.$apply(function () {
scope.$eval(attrs.schdKeyenter, { 'someArg': element.val() });
});
event.preventDefault();
}
});
};
});
Usage:
<input type="text" schd-keyenter="onEnterPressed(someArg)">
When onEnterPressed() is called, someArg is undefined.