0

I'm new to angular.js and i have been having trouble getting form input value.

So i have looked for an answer all over including stackoverflow i could not find any answer.

I want to get the input values using the controller but on each attempt i try i get in the console that its undefined on just using either an object or just text

here is the javascript code:

$scope.url = ''; $scope.user = { password : '', repassword : '' }; $scope.registerUser = function() { $log.info($scope.email); $log.info($scope.user); } 

here is the html code:

<table class="table-responsive"> <tbody> <form class="form-inline" action="" method="post"> <div class="form-group"> <tr> <td><label for="email">E-mail</label></td> <td> <div class="input-group"> <input type="email" class="form-control" name="email" ng-model="email"> <div class="input-group-addon"><span class="glyphicon glyphicon-envelope"></span></div> </div> </td> </tr> </div> <div class="form-group"> <tr> <td><label for="password">Password</label></td> <td><input type="password" class="form-control" name="password" ng-value="user.password"><td> </tr> </div> <div class="form-group"> <tr> <td><label for="Repassword">Reenter Password:</label></td> <td><input type="password" class="form-control" name="Repassword" ng-value="user.repassword"></td> </tr> </div> <tr><td><input class="btn btn-default" type="button" value="Register" ng-click="registerUser()"></td></tr> </form> </tbody> </table> 
2
  • could it be because you are using ng-value instead of ng-model?
    – Rob
    CommentedSep 12, 2015 at 7:10
  • Welcome to StackOverflow, please accept the answer that has worked for youCommentedSep 12, 2015 at 8:06

1 Answer 1

3

You're using ng-value instead of ng-model:

<input type="password" ng-model="user.password"> <input type="password" ng-model="user.repassword"> 

You might also want to pass in user to your ng-click for convenience and less typing in the function:

ng-click="registerUser(user)" $scope.registerUser = function(user) { console.log(user); } 
2
  • @Rob It makes for less typing in the function, so I usually do it anyways.CommentedSep 12, 2015 at 7:14
  • @JohnMuchoki Glad to hear, don't forget to mark it as the answer :)CommentedSep 12, 2015 at 7:19

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.