user1751287
user1751287

Reputation: 501

angularjs clean input field after submission

trying to clear input filed after button is clicked and post saved with angular but it does not work. here is a simple code

<!--html-->
<input type="text" ng-model="addField"/>
<button type="button" ng-click="addPost(item)">add</button>

/*script*/
$scope.addField = '';
function addPost(item) {
    /*code for adding*/
    $scope.addField = "";
}

Upvotes: 2

Views: 73

Answers (1)

Gaurav Kumar Singh
Gaurav Kumar Singh

Reputation: 1570

Use a object instead of string, Try this

<!--html-->
<input type="text" ng-model="form.addField"/>
<button type="button" ng-click="addPost(item)">add</button>

/*script*/
$scope.form = {};
$scope.addPost = function(item) {
    /*code for adding*/
    $scope.form = {};
}

Upvotes: 2

Related Questions