2016-11-03 3 views
0

Ich habe ein Formular für die Passwortaktualisierung. HTML:Clear Wert in einem Textfeld in AngularJS ohne Manipulation von Daten in ng-Modell

<div class="profile-fields"> 

       <p>Please provide your profile details</p> 

       <div class="field"> 
        <label for="username">User Name</label> 
        <input type="text" name="username" value="" placeholder="UserName" ng-model="profile.name" ng-disabled="true" /> 
       </div> 

       <div class="field"> 
        <label for="password">Password:</label> 
        <input type="password" name="password" placeholder="Password" ng-model="profile.password" value="" validator="required" required-error-message="Password is required" valid-method="watch" /> 
       </div> 
       <div class="field"> 
        <label for="password">Retype Password:</label> 
        <input type="password" name="password1" value="" placeholder="Password" ng-model="password1" validator="required" required-error-message="Password is required" valid-method="watch" /> 
       </div> 
      </div> 

Das neue Passwort aus dem ersten Feld Kennwort gesendet wird, mit ng-model="profile.password"

Controller:

myApp.controller('profileController', ['$scope', 'userResolved', 'userServices', '$location', function ($scope, userResolved, userServices, $location) { 

    $scope.oldPassword = userResolved.data.password; 
    $scope.profile = userResolved.data; 
$scope.cancelProfile = function() { 


     $location.path("/dashboard"); 


    } 
    $scope.updateProfile = function() { 

     if ($scope.profileForm.$valid && $scope.profile.password == $scope.password1) { 
      if ($scope.profile.password != $scope.oldPassword) { 
       userServices.saveProfile($scope.profile).then(function (result) { 
        if (!result.error) { 
         alert("Profile updated!!! Please login again with new password."); 
         $location.path("/logout"); 
        } 
       }) 
       .catch(function (data) { 
        $scope.error = data.data; 
       }); 
      } 
      else { 
       $scope.error = "Password cannot be same as before!!" 

      } 

     } 
     else { 
      $scope.error = "Passwords mismatch!!" 
     } 
    }; 
}]); 

Das Problem ist, dass das Modell auf Seite laden wird das aktuelle Passwort Anzeige in das erste Passwort Textfeld. Der Benutzer muss das aktuelle Passwort manuell aus dem ersten Textfeld löschen, um das neue einzugeben. Ich kann nicht einfach die profile.password löschen, weil ich es für die Validierung verwende. Können wir den Wert im Element beim Laden der Seite auf eine Weise löschen, dass wir das ng-Modell nicht manipulieren?

Das Textfeld sollte beim Laden der Seite nicht das aktuelle Passwort anzeigen. Wie kann ich das erreichen?

+0

aber es zeigt nur "Punkte" so was ist falsch damit? – rakaz

+2

Standardmäßig speichern Sie den Kennwortwert NIEMALS in der Variablen, nachdem Sie ihn verwendet haben. Sobald Sie sich angemeldet haben, löschen Sie die Passwort-Variable. Wenn Sie dies einhalten, wird Ihr Problem gelöst. – FDavidov

+0

Könnten Sie bitte Ihren Code in 'PLNKR' eingeben? –

Antwort

1

Erstellen Sie eine neue Variable, und weisen Sie ihr das Kennwort zu, und löschen Sie dann die Modellvariable.

var myPassword = profile.password; 

profile.password = ""; 
Verwandte Themen