title: Get value of input field from Angular directive
body: <p>I'm using the directive from <a href="https://stackoverflow.com/a/17364716/1377021">this answer</a> to run a function when the enter key is pressed in an input field.</p>
  
  <p>How can I pass the value of the input field <code>element.val()</code> to the function the directive calls? Or pass the input field <code>element</code> to the function, to clear the value after it's retrieved.</p>
  
  <p><strong>HTML</strong></p>
  
  <pre><code>&lt;input type="text" ng-enter="newField()" /&gt;
  </code></pre>
  
  <p><strong>JS</strong></p>
  
  <pre><code>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();
              }
          });
      };
  });
  </code></pre>