I have a reset function in angular to clear all the fields in a form. If I do something like:
<a href="#" ng-click="resetForm()">reset</a>
$scope.resetForm = function() {
$scope.someForm = {};
}
Everything works fine. But I want to use this function for multiple forms on the site. If I pass the form object in like:
<a href="#" ng-click="resetForm(someForm)">reset</a>
$scope.resetForm = function(form) {
$scope.form = {};
}
Then it won't work. Can someone explain to me why this would be happening?
You can also do:
It works great for radio buttons and checkboxes.
you can try this : Deploy your function inside form button reset , in this way ...
You have 2 problems:
someForm
of current scope.form = {}
, it does not work because it only changes the reference of the parameter, not the reference of the passed insomeForm
.Try:
Or
instead of:
In your plunk, I see that you're not separating the view from the model. You should do it for separation of concerns and to avoid problems that might happen when you clear all the fields (including DOM form object's fields).
http://plnkr.co/edit/x4JAeXra1bP4cQjIBld0?p=preview