Tutorial 17 – how to use ng-submit in sngularjs

How to use ng-submit in sngularjs?

Directive ng-submit in sngularjs
This sample will help you know about using ng-submit in AngularJS.



 <html>  
   <head>  
     <title>Angular JS Model</title>  
     <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>  
     <script>  
       angular.module('MyForm', [])  
           .controller('myController', ['$scope', function($scope) {  
 $scope.login = function () {  
             if ($scope.username == 'admin' && $scope.password == '123456') {  
               alert(‘Login successfully.’);  
             }  
             else {  
               alert('Login failed.');  
             }  
           };  
            }]);  
     </script>  
   </head>  
   <body ng-app="MyForm" name = “myform” ng-submit="login()" >  
 User name: <br />  
     <input type="text" name="userName" ng-pattern="/^([a-zA-Z0-9]+)$/" ng-model="username" ng-trim="true" required ng-minlength="3" ng-maxlength="10" /> <br />  
     Password: <br />  
     <input type="text" name="userPass" ng-model="password" required ng-minlength="3" ng-maxlength="10" ng-trim="true"> <br /><br />  
     <input type="submit" value='Login' />   
 </body>  
  </html>  


1 comment:

Popular Posts