title: how to pass data to server which were fetched from database to text boxes, using ng-model,ng-value or any other method
body: <p>I fetch data from database and show them in text boxes using ng-value. Then I tried to bind text box's data using ng-model and pass them again to database in order to update database data.It works fine only if I changed values in both text boxes.But this method doesn't take values which were loaded using ng-value.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>$scope.showData = function(userName) {
    //$scope.userName=userName;
    console.log(userName);
    $http.get('/api/personalData/' + userName)
      .success(function(data) {
        if (data.error) {
          $scope.errorMsg = data.error;
          console.log("Data havn't retrieved");
  
        } else {
          $scope.personalData = data.personalData;
          console.log("Data retrieved successfully");
          console.log($scope.personalData);
        }
  
      });
  };
  $scope.editUser = function(userName) {
    $scope.personal = {
      'age': $scope.personal.age
    };
    //$scope.userName=userName;
    console.log("name:" + userName);
    $http.post('/api/editPersonalData/' + userName, $scope.personal)
      .success(function(data) {
        if (data.error) {
          $scope.errorMsg = data.error;
          console.log("Data havn't been sent");
        } else {
          console.log("Data sent successfully");
          console.log(data.personalData);
        }
  
      });
  };
  
  
  In Node.js file,
  
    app.get('/api/personalData/:userName', function(req, res) {
      var userName = req.params.userName;
      con.query("Select * from users where username=?", [userName], function(err, result) {
        if (!err) {
          res.json({
            personalData: result
          });
          console.log("successfully sent");
          console.log({
            personalData: result[0]
          });
        } else {
          res.json({
            error: "Error while performing query"
          });
          console.log("Error while performing query:" + err);
        }
      });
    });
  
  app.post('/api/editPersonalData/:userName', function(req, res) {
    var userName = req.params.userName;
  
  
    var name = req.body.name;
    var age = req.body.age;
    console.log(userName + "," + name + "," + age);
    //console.log(name+","+age+","+userName);
    con.query("UPDATE users SET name=?,age=? WHERE username=?", [name, age, userName], function(err, result) {
      if (!err) {
        res.json({
          success: 'data updated'
        });
        console.log("success");
      } else {
        res.json({
          error: 'Error while performing query'
        });
        console.log("Error while performing query." + err);
      }
    });
  });</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"&gt;&lt;/script&gt;
  &lt;form name="updateform"&gt;
    &lt;div class="modal-body row"&gt;
      &lt;div class="form-group"&gt;
        &lt;label class="control-label col-sm-2"&gt;Name:&lt;/label&gt;
        &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control text-right" ng-value="personalData[0].name" ng-model="personal.name" required autofocus/&gt;
        &lt;/div&gt;
        &lt;br&gt;
        &lt;br&gt;
        &lt;br&gt;
        &lt;label class="control-label col-sm-2"&gt;Age:&lt;/label&gt;
        &lt;div class="col-sm-10"&gt;
          &lt;input type="text" class="form-control text-right" ng-value="personalData[0].age" ng-model="personal.age" required autofocus/&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
    &lt;div class="modal-footer"&gt;
      &lt;button type="button" class="btn btn-success" ng-click="editUser(personalData[0].username)"&gt;Save&lt;/button&gt;
      &lt;button type="button" class="btn btn-warning" data-dismiss="modal"&gt;Close&lt;/button&gt;
    &lt;/div&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>