J. Davidson J. Davidson - 4 months ago 15
Javascript Question

Resetting form after submit in Angularjs

Hi I have a form which does update on button click.

$scope.action = "Update";
var id = $routeParams.editId;
scope.item = updateRecord.get({ id: id });


Once the item is updated it doesn't remove the entered information in the form fields. I was wondering what is available in angularjs to add in the above code after udpating so that it also clears to form.
Thanks

Answer

You can reset a form by, $scope.formName.$setPristine(); but if you're binding a model object to your inputs, you need to take care of clearing those too, ie:

$scope.currentRecord={};

Comments