Angularjs将页面中的所有表单重置为原始状态 [英] Angularjs reset all forms in a page to pristine state
问题描述
我在Angularjs应用程序中有一个搜索按钮,当我点击搜索按钮时,会呈现不同的小部件,每个小部件都有< form>
一个表单验证失败,表单状态为$ dirty。如果我再次搜索不同的值并想清除以前的错误。
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.
如何重新点击搜索按钮,将所有表单重置为$ pristine?
How can i reset all the forms to $pristine on clicking search button again?
推荐答案
您可以使用 $ scope.formName。$ setPristine(true)
。这在angular的更高版本中可用,并用于将表单重置为原始状态
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
这篇关于Angularjs将页面中的所有表单重置为原始状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!