ionic angularjs实现登录验证|Ionic+AngularJS实现登录和注册带验证功能

更新时间:2021-06-17    来源:js教程    手机版     字体:

【www.bbyears.com--js教程】

登录:

 

 代码如下

  

  

  

  

  

  

  

  

  

  <script src="lib/ionic/js/ionic.bundle.js"></script>

  

  <script src="cordova.js"></script>

  

  <script src="js/app.js"></script>

  <script src="js/Login.js"></script>

  

    

      

        用户登录

      

      

        

          

            

              

                

                

                

                  用户名是必须的

                

              

            

            

              

                

                word" name="password" ng-model="password" id="password" placeholder="密码" required>

                

                  密码是必须的

                

              

            

          

          

            

          

        

      

   

  

  <script>

 'use strict';  

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

myApp.controller('myCtrl',['$scope', '$http',function($scope, $http){

 // $scope.formModel = {};

 $scope.submitted = false;

 $scope.onSubmit = function(){

  if ($scope.myForm.$valid) {

    var param = {

        User: $scope.user,

        Pwd: $scope.password

      }

    $http.post('someurl',param)

   .success(function(data){

    console.log(':)');

   })

   .error(function(data){

    console.log(':(');

   });

  console.log(param);

}else{

  $scope.submitted =true;

}

 }

}]);

  </script>

 

 

不填写信息登录就会如图所示:

注册:

 

 代码如下

  

  

  

  

  

  

  

  <script src="lib/ionic/js/ionic.bundle.js"></script>

  

  <script src="cordova.js"></script>

  

  <script src="js/app.js"></script>

  <script src="js/Register.js"></script>

  

  

  

  

    

      

        用户注册

      

      

        

          

            

              

                

                

                

                  用户名是必须的

                

              

            

            

              

                

                

                

                  密码是必须的

                

              

            

            

              

                

                

                

                  确认密码是必须的

                

                

                  两次密码输入不一致

                

              

            

          

          

            

          

    

  

   

 <script>

   'use strict';  

 varmyApp = angular.module('myApp',[]);

myApp.controller('myCtrl',['$scope','$http',function($scope, $http){

 // $scope.formModel = {};

 $scope.submitted =false;

 $scope.onSubmit =function(){

  if($scope.myForm.$valid) {

    varparam = {

        User: $scope.user,

        Pwd1: $scope.password1,

        Pwd2:$scope.password2

      }

    $http.post('someurl',param)

   .success(function(data){

    console.log(':)');

   })

   .error(function(data){

    console.log(':(');

   });

  console.log(param);

}else{

  $scope.submitted =true;

}

 }

}]);

  </script>

 

不填写信息注册就会出现下图:

本文来源:http://www.bbyears.com/wangyezhizuo/124241.html