Reset form on clicking event in AngularJS

2019-09-20 03:09发布

问题:

Can any one suggest an easy way to reset or reload an HTML form on click event in AngularJS?

回答1:

You can use angular.copy({},yourform) to copy empty array to your form object as below

$scope.resetForm = function(form) {
     angular.copy({}, form);
}

Html

<form>
    <input type="text" ng-model="myForm.myName" />
    <input type="text" ng-model="myForm.adress" />
    <input type="button" value="reset" ng-click="resetForm(myForm)" />
</form>

Working fiddle