2016-10-04 65 views
-2

我需要验证登录功能。我添加了我的Login.html文件和LoginController.js文件。我想验证这从使用这个JavaScript。这是angularjs代码。之后,我必须为此代码设置php网址。如何验证表单使用if语句中的javascript角

的login.html

$scope.submitForm = function() { 
 

 
    \t \t var user_email = user_email; 
 
    \t \t var user_password = user_password; 
 

 
    \t \t if(user_email && user_password){ 
 

 
    \t \t \t console.log(user_email); 
 
     
 
    \t \t } 
 

 
    \t \t 
 

 
    \t };
<div ng-controller="LoginController"> 
 
     <form name="userForm" ng-submit="submitForm()"> 
 

 
     <div class="list"> 
 
      <label class="item item-input"> 
 
      <span class="input-label">Username</span> 
 
      <input type="text" name="user_email" ng-model="user.user_email" required> 
 
      </label> 
 
      <label class="item item-input"> 
 
      <span class="input-label">Password</span> 
 
      <input type="password" name="user_password" ng-model="user.user_password" required> 
 
      </label> 
 
     </div> 
 

 
     <span ng-show="userForm.user_email.$touched && userForm.user_email.$invalid">The Username is required.</span> </br> 
 
     <span ng-show="userForm.user_password.$touched && userForm.user_password.$invalid">The Password is required.</span> 
 

 
     <button class="button button-block button-positive activated">Sign In</button> 
 
     <button onclick="location.href='#/login/:friendId/register/';" class="button button-block button-positive activated">Register</button> 
 
     
 
     </form> 
 
     </div>

+0

我猜你以前没有做任何研究吗? –

+0

我没有任何想法请你给我回答 – moni123

+0

https://scotch.io/tutorials/angularjs-form-validation –

回答

0

在你提供的代码所做的更改,对注册/登录的点击就可以调用submitForm()功能通过ng-click评估形式values.Check下面的工作模型代码片段。

angular.module('myApp', ['ng']) 
 

 
.controller('LoginController', ['$scope', 
 
    function($scope) { 
 
    $scope.user = {}; 
 
    $scope.submitForm = function() { 
 

 
     var user_email = $scope.user.user_email; 
 
     var user_password = $scope.user.user_password; 
 

 
     if (user_email && user_password) { 
 

 
     console.log(user_email); 
 

 
     } 
 
    }; 
 
    } 
 
]);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 
 
<div ng-app="myApp" ng-controller="LoginController"> 
 
    <form name="userForm"> 
 

 
    <div class="list"> 
 
     <label class="item item-input"> 
 
     <span class="input-label">Username</span> 
 
     <input type="text" name="user_email" ng-model="user.user_email" required>{{user.user_email}} 
 
     </label> 
 
     <label class="item item-input"> 
 
     <span class="input-label">Password</span> 
 
     <input type="password" name="user_password" ng-model="user.user_password" required>{{user.user_password}} 
 
     </label> 
 
    </div> 
 

 
    <span ng-show="userForm.user_email.$touched && userForm.user_email.$invalid">The Username is required.</span> 
 
    </br> 
 
    <span ng-show="userForm.user_password.$touched && userForm.user_password.$invalid">The Password is required.</span> 
 

 
    <button class="button button-block button-positive activated">Sign In</button> 
 
    <button ng-click="submitForm()" class="button button-block button-positive activated">Register</button> 
 

 
    </form> 
 
</div>

+0

'ng-click'然后我添加了这个。它不会工作 – moni123

+0

你有没有试过我提供的代码片段在这里工作! –