我使用angular.js 1.1.5版有 $ setPristine
的形式控制器。但这种方法似乎并不清除与字段相关联的任何错误。下面的code对我的作品,但我不知道这是否是清除错误的正确方法。有什么建议?
在我的控制器:
如果($ scope.myform){ 。$ scope.myform $ setPristine(); 删除$ scope.myform.myfield $ error.myvalidator。}
解决方案
$的setPristine()仅清除脏标志的形式,但在表单验证与$ setValidity()清除
I am using angular.js version 1.1.5 which has $setPristine
on the form controller. But this method does not seem to clear any errors associated with fields. The code below works for me, but I am not sure whether this is the right way to clear errors. Any advice?
In my controller:
if ($scope.myform) {
$scope.myform.$setPristine();
delete $scope.myform.myfield.$error.myvalidator;
}
解决方案
The $setPristine() clears only the flag dirty in a form but the validation in a form are cleared with $setValidity()