CodePen

HTML

            
              Shows how to use a directive to submit a form by hitting 'enter' while in a textarea.<br/>A carriage return is still possible using shift+enter.

<div ng-app="testApp" ng-controller="MyController">
  <textarea ng-model="foo" enter-submit="submit()"></textarea><br/>
  <textarea ng-model="foo" enter-submit="submit()"></textarea><br/>
  Last submitted text: {{ lastSubmitted }}<br/>
</div>
            
          
!

↑ Insert the most common viewport meta tag

CSS

            
              * {
  padding: 0;
  margin: 0;
  font-family: 'arial', sans-serif;
}

div {
  text-align: center;
  margin: 50px;
}

textarea {
  width: 400px;
  height: 100px;
}
            
          
!
? ?
? ?
Must be a valid URL.
+ add another resource
via CSS Lint

JS

            
              var app = angular.module('testApp', []);

function MyController($scope) {
 
  $scope.foo = ""
  $scope.lastSubmitted = ""
  
  $scope.submit = function() {
    $scope.lastSubmitted = $scope.foo; 
  }
}

app.directive('enterSubmit', function () {
    return {
      restrict: 'A',
      link: function (scope, elem, attrs) {
       
        elem.bind('keydown', function(event) {
          var code = event.keyCode || event.which;
                  
          if (code === 13) {
            if (!event.shiftKey) {
              event.preventDefault();
              scope.$apply(attrs.enterSubmit);
            }
          }
        });
      }
    }
  });

            
          
!
Must be a valid URL.
+ add another resource
via JS Hint
Loading ..................