Angularjs reset all forms in a page to pristine st

2019-07-25 09:41发布

问题:

I have a search button in Angularjs application, when i click search button that will render different widgets each widget have <form> that submit data to the server if any one form validation fails and the state of the form is $dirty. if I search again with different values and wants to clear the previous errors.

How can i reset all the forms to $pristine on clicking search button again?

回答1:

you can use $scope.formName.$setPristine(true). This is available in later versions of angular and is used to reset the forms to pristine state