AngularJS clear input not working on data change

Handsontable JavaScript Spreadsheet Most popular component for web apps

Problem: I simply want the value to be cleared from the input.
Solution: There is a workaround below.

I have this input and it is bound to a model which is held within the controller and a function in the controller sets it to empty (”) but the input still has the value set. I’ve seen to try use $scope.form.$setPristine(); to clear the form.

Now I see this error:

“TypeError: Cannot call method ‘$setPristine’ of undefined”


From the docs: “Each form directive creates an instance of FormController.” So does this mean it only works with a form directive? It’s not in the api docs but the setPristine() function uses the form name as the controller reference.

If I log the values of the form I get this:

And if I use any of the following i get that error above:

In the end the reset worked fine so I’m using that for now. Still no idea why setPristine() is not working. If you have any ideas please leave a comment. Thanks.


Sam Deering

Sam Deering

Sam is a web developer, online entrepreneur and investor. In his spare time he enjoys coding, playing chess and sharing what he learns with others.

4 thoughts on “AngularJS clear input not working on data change

  1. i have exactly same problem…and however mange to use reset()…but still my required form validation shows

  2. I found a solution:First,define a button in the form: button(ng-click=commit(form)), then write something in the controller:$scope.commit = function(){ form.$setPristine();} Hope it helps.

Leave a Reply

Your email address will not be published. Required fields are marked *