HTML

<form ng-controller="updatecontroller" ng-submit="updateUser()"><label class="control-label">First Name</label>
    <input type="text"  ng-model="user.userFirstName">
    <label class="control-label">Last Name</label>
    <input type="text"  ng-model="user.userLastName" ><button type="submit" ng-click="updateUser()">Update</button>
</form> 

JS

app.controller('updatecontroller', function ($scope, $http, $cookieStore) {

$http.get('http://localhost:8080/myapp/user/'.concat($scope.getUserId) + '?access_token=' + $cookieStore.get("access_token")).
        then(function (response) {
            $scope.user = response.data;
        });$scope.user = {"id": "","userFirstName": "","userLastName": ""}

$scope.updateUser = function () {

    var url = "http://localhost:8080/myapp/user/".concat($scope.getUserId) + "?access_token=" + $cookieStore.get("access_token");
    var method = "PUT";
    $http({
        method: method,
        url: url,
        data: angular.toJson($scope.user),
        headers: {
            'Content-Type': 'application/json'
        }
    })
};});

values will appear in text field. i have to update. the values are getting updated in database. but what i want is.. the updated values should not clear after submit the form.

Thanks!

share|improve this question
    
share updateUser() method ? – Niklesh Nov 24 '16 at 10:15
    
Also note that your submit button is outside the form ... which I guess is why you have had to give it the ng-click. – haggisandchips Nov 24 '16 at 10:16
    
Now you've moved the button inside the form you need to remove the ng-click otherwise updateUser will be executed twice. Could you create a plunkr showing the failing behaviour (without the $http stuff). – haggisandchips Nov 24 '16 at 10:44
    
what code you aare executing after the updateUser() method? – Sravan Nov 26 '16 at 5:34
up vote 0 down vote accepted
You can empty the input filed after get the response from HTTP request

$scope.updateUser = function () {
$http({
    method: 'POST',
    url: 'myUri', 
    data: 'your data'
    headers:'header'
}).then(
    function(res) {
      $scope.user = {"id": "","userFirstName": "","userLastName": ""} //clear the input field here

    },
    function(err) {

    }
);
}
share|improve this answer

Place your Submit Button inside the Form Element then try it it will clear the input after the submission.

share|improve this answer
    
Please Asking more detailed? im Not understanding what you need? – Sathishkumar Nov 24 '16 at 11:21

your updateUser() method seems to be the problem. It's probably clearing user.userFirstName & user.userLastName (or the whole user)

please show us what updateUser() is doing to be sure

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.