-1

Here is the submit button:

 <input type="submit" ng-click="Showdata()"  class="btn blue pull-right" Text="" />

Here is the text box for email:

 <input type="text" ng-model="texttype" class="form-control" ng-class="eml" placeholder="Enter Email" />

here is the textbox for pass:

  <input type="password" ng-model="passwordtype" class="form-control" ng-class="pass" placeholder="Enter Password" />

Here submit working for the mouse click..But how can i work on enter click?? Here i am using angularjs. How can i submit on both mouse click and enter key press?

Arun Kumaresh
  • 6,211
  • 6
  • 32
  • 50
asasasaa
  • 105
  • 2
  • 12

3 Answers3

0

Try using ng-enter directive. I think this will help you.

var $scope;
var app = angular.module('miniapp', []).filter('moment', function() {
    return function(dateString, format) {
        return moment(dateString).format(format);
    };
});

app.directive('ngEnter', function () {
    return function (scope, element, attrs) {
        element.bind("keydown keypress", function (event) {
            if(event.which === 13) {
                scope.$apply(function (){
                    scope.$eval(attrs.ngEnter);
                });
 
                event.preventDefault();
            }
        });
    };
});

function Ctrl($scope) {
    $scope.DoWork = function(){
          alert('Hello World! ' + $scope.MyText);  
    };
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
<div ng-app="miniapp">
    <div ng-controller="Ctrl">
        <input ng-enter="DoWork()" ng-model="MyText" />
    </div>    
</div>
Nitheesh
  • 19,238
  • 3
  • 22
  • 49
0

you need to use the form tag with ng-submit

<form name="sampleForm" ng-submit="Showdata()">

  <input type="text" ng-model="texttype" class="form-control" ng-class="eml" placeholder="Enter Email" />    
  <input type="password" ng-model="passwordtype" class="form-control" ng-class="pass" placeholder="Enter Password" />
  <input type="submit"  class="btn blue pull-right" Text="" />   

</form>
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80
0

Add one class named like "searchTextbox" in input field And then use that code

    $('.searchTextbox').keypress(function (event) {
                if (event.which == 13) {
                    $scope.Showdata();
                }
            });


<input type="text" ng-model="texttype" class="form-control searchTextbox " ng-class="eml" placeholder="Enter Email" />
Jinal Mehta
  • 171
  • 6