javascript - Submit with button, on enter, outside of form with only Angular -


what solution implement angular "form", wanted submit on enter key press, can't rearrange elements fit in <form> element. instance this:

<div>     <input/>     <input/>      //this might act kind of custom built select     <ul>         <li></li>     </ul>      <form></form> //dropzone form instance.      <button type="submit" ng-click="submitfunction()">submit</button> </div> 

i want user able hit enter while focus on of these elements(not true form elements), , have form submit(validation passing of course). solution should purely angualr(if possible). i'd rather didn't use complex css positioning, don't want have rearrange , muddle html structure.

i saw solution online custom "ngenter" type directive thought had promise don't think on team gonna solution. i'd know how else 1 might approach this.

see article more info.

here's snippet showing how conditionally log console using ng-keypress:

angular.module('myexample', [])    .controller('mycontroller', ['$scope', function($scope) {      $scope.myfunction = function() {       console.log('hi!');      }    }]);
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>    <div ng-app="myexample">    <div ng-controller="mycontroller">      <input placeholder="type something" ng-keypress="$event.which === 13 && myfunction()">    </div>  </div>


Comments