2016-06-28 32 views
-1

當我嘗試使用無效的用戶名和密碼登錄時,它會將消息顯示爲「無效的用戶名或密碼」。當使用錯誤的用戶名或密碼時,如何清除密碼字段 - angularjs

但是,如果它無效的用戶名或密碼,然後密碼字段爲重置。

任何人都可以請幫助我如何做到這一點?

我的控制器:

function login() { 
      vm.dataLoading = true; 
      var baseUrl = $location.$$absUrl.split('#')[0]; 
      AuthenticationService.Login(vm.username, vm.password, baseUrl, function (response) { 
       console.log(response); 
       if(response.success !== undefined){ 
        FlashService.Error(response.message, true); 
       } else { 
        if (response.json.response.statuscode == 0) { 
         AuthenticationService.SetCredentials(vm.username, vm.password, response.json.response.candidateid, response.json.response.profilestatus); 
         //(response.json.response.profilestatus < 15) ? $location.path('/otp') : $location.path('/'); 

         $location.path('/') 
        } else { 
         FlashService.Error(response.json.response.statusmessage); 
         vm.dataLoading = false; 
        } 
       } 
      }); 
     }; 

我的HTML:

<div class=" well tab-content"> 
    <div role="tabpanel" class="tab-pane active" id="personal"> 
     <div class="row"> 
      <div class="col-sm-10 col-lg-offset-1"> 
       <form name="form" ng-submit="vm.login()" role="form"> 
        <div class="form-group" ng-class="{ 'has-error': form.username.$dirty && form.username.$invalid }"> 
         <label for="username">Email</label> 
         <input type="email" placeholder="Email" name="username" id="username" class="form-control" ng-model="vm.username" required /> 
         <span ng-show="form.username.$dirty && form.username.$error.required" class="help-block">Email required</span> 
         <span ng-show="form.username.$dirty && form.username.$error.required" class="help-block">Invalid Email Id</span> 
        </div> 
        <div class="form-group" ng-class="{ 'has-error': form.password.$dirty && form.password.$error.required }"> 
         <label for="password">Password</label> 
         <input type="password" name="password" id="password" class="form-control" placeholder="Password" ng-model="vm.password" required /> 
         <span ng-show="form.password.$dirty && form.password.$error.required" class="help-block">Password required</span> 
        </div> 
        <div class="form-actions"> 
         <button type="submit" ng-disabled="form.$invalid || vm.dataLoading" class="btn btn-info">Login</button><a href="#/resetpassword" class="btn btn-link">Forgot Password?</a> 
         <img ng-if="vm.dataLoading" src="data:image/gif;base64,R0lGODlhEAAQAPIAAP///wAAAMLCwkJCQgAAAGJiYoKCgpKSkiH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCgAAACwAAAAAEAAQAAADMwi63P4wyklrE2MIOggZnAdOmGYJRbExwroUmcG2LmDEwnHQLVsYOd2mBzkYDAdKa+dIAAAh+QQJCgAAACwAAAAAEAAQAAADNAi63P5OjCEgG4QMu7DmikRxQlFUYDEZIGBMRVsaqHwctXXf7WEYB4Ag1xjihkMZsiUkKhIAIfkECQoAAAAsAAAAABAAEAAAAzYIujIjK8pByJDMlFYvBoVjHA70GU7xSUJhmKtwHPAKzLO9HMaoKwJZ7Rf8AYPDDzKpZBqfvwQAIfkECQoAAAAsAAAAABAAEAAAAzMIumIlK8oyhpHsnFZfhYumCYUhDAQxRIdhHBGqRoKw0R8DYlJd8z0fMDgsGo/IpHI5TAAAIfkECQoAAAAsAAAAABAAEAAAAzIIunInK0rnZBTwGPNMgQwmdsNgXGJUlIWEuR5oWUIpz8pAEAMe6TwfwyYsGo/IpFKSAAAh+QQJCgAAACwAAAAAEAAQAAADMwi6IMKQORfjdOe82p4wGccc4CEuQradylesojEMBgsUc2G7sDX3lQGBMLAJibufbSlKAAAh+QQJCgAAACwAAAAAEAAQAAADMgi63P7wCRHZnFVdmgHu2nFwlWCI3WGc3TSWhUFGxTAUkGCbtgENBMJAEJsxgMLWzpEAACH5BAkKAAAALAAAAAAQABAAAAMyCLrc/jDKSatlQtScKdceCAjDII7HcQ4EMTCpyrCuUBjCYRgHVtqlAiB1YhiCnlsRkAAAOwAAAAAAAAAAAA==" /> 

         <hr> 

        </div> 
+0

儘管如此請求尿急,**後,我已經提到過很多次給你**。任何意見? – halfer

+0

你試過下面的答案嗎? – abdoutelb

回答

1

您需要的vm.password復位控制器,因爲你的密碼輸入 「NG-模式」 是VM .password

當您收到錯誤消息時,請嘗試:

  • 要設置密碼爲空:

vm.password = "";

  • 要設置密碼未定義:

vm.password = undefined;

  • 要刪除屬性密碼:

delete vm.password;

+0

謝謝,我知道了 –

+0

我很抱歉,他想把空密碼,所以我給了他答案。我是新的,我不知道如何改善答案。是直接的,但在我看來是清楚而有效的。他可以重置密碼,因爲密碼「ng-model」是vm.password。我認爲你也可以編輯我的答案並改進它,這也有幫助。 – Mikel

相關問題