angularjs验证表单

时间:2017-03-02 07:40:55

标签: angularjs html5

我所有我是angularjs的新人请有人告诉我这个代码的错误我的html在这里:

<div class="form">
   <div id="signup">
      <h1>Welcome Back!</h1>
      <form action="/" name="loginForm" method="post" ng-submit="sendLoginData()>
         <div class="field-wrap">
            <input type="email"required autocomplete="off" name="userEmail" ng-model="user.name" placeholder="E-mail" required/>
            <p ng-show="loginForm.userEmail.$error.required">Please Enter  Your E-mail</p>
         </div>
         <div class="field-wrap">
            <input type="password"required autocomplete="off" name="userPassword" ng-model="user.password" placeholder="Password" required/>
            <p ng-show="loginForm.userPassword.$error.required">Please Enter Your Password</p>
         </div>
         <span class="forgot"><a href ="#sign-up">Sign up</a></span>
         <p class="forgot"><a href="#forgotpassword">Forgot Password?</a></p>
         <input type="submit" class="button button-block" ng-disabled="loginForm.$invalid" value="Log IN"/>
      </form>
   </div>
</div>

1 个答案:

答案 0 :(得分:0)

您可以使用此

替换您的代码
<div class="form">
       <div id="signup">
          <h1>Welcome Back!</h1>
          <form action="/" name="loginForm" method="post" ng-submit="sendLoginData()">
             <div class="field-wrap">
                <input type="email"required autocomplete="off" name="userEmail" ng-model="user.name" placeholder="E-mail" required/>
                <p ng-show="loginForm.userEmail.$touched && loginForm.userEmail.$error.required">Please Enter  Your E-mail</p>
             </div>
             <div class="field-wrap">
                <input type="password"required autocomplete="off" name="userPassword" ng-model="user.password" placeholder="Password" required/>
                <p ng-show="loginForm.userPassword.$touched && loginForm.userPassword.$error.required">Please Enter Your Password</p>
             </div>
             <span class="forgot"><a href ="#sign-up">Sign up</a></span>
             <p class="forgot"><a href="#forgotpassword">Forgot Password?</a></p>
             <input type="submit" class="button button-block" ng-disabled="loginForm.$invalid" value="Log IN"/>
          </form>
       </div>
    </div>