2016-11-17 56 views
1

我有两个字段的密码和确认密码,并在标签中的错误消息,即“密码不匹配”,但它应显示在密码输入不正确的确认密码字段而不是它已经显示当我打开表单时。角JS确认密码信息已经显示

HTML

<div class="form-group" ng-class="{ 'has-error': submitted && CreateClientAdminForm.password.$error.required || CreateClientAdminForm.password.$error.pattern }" > 
       <label class="col-md-4 control-label" for="password">Password*</label> 
       <div class="col-md-4"> 
        <input id="password" name="password" type="password" placeholder="Password" class="form-control input-md" ng-model="clientAdmin.User.UserPassword" ng-pattern="regex.Password" ng-maxlength="20" required autofocus> 
        <span ng-show="submitted && CreateClientAdminForm.password.$error.required" class="help-block">Password can not be empty</span> 

        <span ng-show="CreateClientAdminForm.password.$error.pattern && CreateClientAdminForm.password.$invalid " class="help-block">Please enter a valid password with at least 6 characters. </span> 
       </div> 
      </div> 
      <!-- Password input--> 
      <div class="form-group" ng-class="{ 'has-error': submitted && CreateClientAdminForm.confirmpassword.$error.required || CreateClientAdminForm.confirmpassword.$error.pattern }" > 
       <label class="col-md-4 control-label" for="confirmpassword">Confirm Password*</label> 
       <div class="col-md-4"> 
        <input id="confirmpassword" name="confirmpassword" type="password" placeholder="Password" class="form-control input-md" ng-model="clientAdmin.User.UserconfirmPassword" ng-pattern="regex.Password" ng-maxlength="20" required autofocus> 
        <span ng-show="submitted && CreateClientAdminForm.confirmpassword.$error.required" class="help-block">Password can not be empty</span> 
        <span ng-show="clientAdmin.User.UserPassword !== clientAdmin.User.UserconfirmPassword" class="help-block"><p>Password mismatch</p></span> 

        <span ng-show="CreateClientAdminForm.confirmpassword.$error.pattern && CreateClientAdminForm.confirmpassword.$invalid " class="help-block">Please enter a valid password with at least 6 characters. </span> 
       </div> 
      </div> 

控制器

globalWeAlertApp.controller("ClientAdminController", function($scope, ClientAdminService,UserCRUDService, toastr, $cookieStore, $window) { 

       //Other functions 

    } 
+1

你可以尝试检查是否'confirmpassword'输入字段是脏的,则其他条件。 –

+0

是的,使用'ng-if'来实现它 –

+0

对不起,我没有得到你请详细说明如何检查? –

回答

0
<span 
ng-show="clientAdmin.User.UserPassword != clientAdmin.User.UserconfirmPassword 
&& (clientAdmin.User.UserPassword != '' && 
lientAdmin.User.UserconfirmPassword != '')" 
class="help-block"> 
<p>Password mismatch</p> 
</span> 
+0

工作!^_ ^谢谢 –