javascript - getting data back to controller from form -


i have form below. when change text fields, shows changes here

<div>     {{authform.email}}{{authform.password}} </div> 

but when try submit form ng-click="signup()" on button, doesn't send me value of text fields. below code

<div class="col-md-12" ng-controller="authctrl">           <div class="row">             <div class="col-md-14">                 <div class="jumbotron">                      <form>                         <div class="createuserdiv"><input type="text" name="email" placeholder="enter email address" ng-model="authform.email"/></div>                         <div class="createuserdiv"><input type="text" name="password" placeholder="enter password" ng-model="authform.password"/></div>                         <div class="createuserdiv"><input type="text" name="confirmpassword" placeholder="confirm password" ng-model="authform.confirmpassword"/></div>                          <p><a class="btn btn-lg btn-success" ng-click="signup()">splendid!<span                                 class="glyphicon glyphicon-ok"></span></a></p>                     </form>                     <div>                         {{authform.email}} {{authform.password}}                     </div>                 </div>              </div>         </div>  </div> 

here js

angular.module('myapp')     .controller('authctrl', function ($scope, $http, $location) {           $scope.signup = function() {              $scope.authform = {};             $scope.authform.email = "";             $scope.authform.password  = "";             $scope.authform.confirmpassword  = "";              var data = {                 "datablob": {                     "email": $scope.authform.email,                     "password":  $scope.authform.confirmpassword                  }             };        console.log($scope.authform.email);      }); 

my console.log coming empty ...null....i not sure why not binding fields data. pretty new angular still trying figure out these things.

stat controller this:

angular.module('myapp') .controller('authctrl', function ($scope, $http, $location) {     $scope.authform = {}; 

then change signup method this:

$scope.signup = function() {     console.log($scope.authform); } 

your values bound, when called $scope.authform = {}; inside of signup, overwriting of values.

also instead of ng-click="signup()" on button, this:

<form ng-submit="signup()"> 

which allow implement validations , submit on [enter] keypress when user in input field

for example, see fiddle


Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

inno setup - TLabel or TNewStaticText - change .Font.Style on Focus like Cursor changes with .Cursor -