设置形式原始状态时取出场错误 [英] removing field errors when setting form to pristine state

查看:81
本文介绍了设置形式原始状态时取出场错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于设置形式原始状态时取出场错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆