设置形式原始状态时取出场错误原始、形式、状态、错误

2023-09-13 05:12:22 作者:20.香蕉你个麻辣

我使用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()