Reset form on clicking event in AngularJS

2019-09-20 02:55发布

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

1条回答
手持菜刀,她持情操
2楼-- · 2019-09-20 03:37

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

查看更多
登录 后发表回答