0

Im trying to set a value of a password input field from the controller but its having no effect

Controller

$scope.passwordDetails.currentPassword = 'madeuppassword';

.

View

<div class="form-group" show-errors>
      <label for="currentPassword">Current Password</label>
      <input type="password" id="currentPassword" name="currentPassword" class="form-control"
             ng-model="passwordDetails.currentPassword" placeholder="Current Password" required>
      <div ng-messages="passwordForm.currentPassword.$error" role="alert">
        <p class="help-block error-text" ng-message="required">Your current password is required.</p>
      </div>
    </div>

Is there something simple im doing wrong?

1
  • The code looks fine and should work. Did you forget to instantiate the controller (either <ANY ng-controller="..."></ANY>, or via a route)? Commented Mar 11, 2016 at 20:20

2 Answers 2

2

If passwordDetails is not initialized from before, your assignment on the scope should throw an error. In case you need the object, then try like this:

$scope.passwordDetails = {
    currentPassword: 'changeme'
};

Here's a working plnkr of your example: http://plnkr.co/edit/J3OfG0ioDJ85egoqTxSG?p=preview

Sign up to request clarification or add additional context in comments.

Comments

0

add the below line before assigning value to nested object.

$scope.passwordDetails = {};
$scope.passwordDetails.currentPassword = 'madeuppassword';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.