在 AngularJS 中,ng-pristine 和 ng-dirty 有什么区别? [英] In AngularJS, what's the difference between ng-pristine and ng-dirty?

查看:22
本文介绍了在 AngularJS 中,ng-pristine 和 ng-dirty 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ng-pristineng-dirty 有什么区别?看来你可以同时拥有 true:

What are the differences between ng-pristine and ng-dirty? It seems you can have both to be true:

$scope.myForm.$pristine = true; // after editing the form

推荐答案

ng-dirty 类告诉您表单已被用户修改,而 ng-pristine class 告诉您该表单尚未被用户修改.所以 ng-dirtyng-pristine 是同一个故事的两个方面.

The ng-dirty class tells you that the form has been modified by the user, whereas the ng-pristine class tells you that the form has not been modified by the user. So ng-dirty and ng-pristine are two sides of the same story.

类设置在任何字段上,而表单有两个属性,$dirty$pristine.

The classes are set on any field, while the form has two properties, $dirty and $pristine.

您可以使用 $scope.form.$setPristine() 函数将表单重置为原始状态(请注意,这是 AngularJS 1.1.x 的功能).

You can use the $scope.form.$setPristine() function to reset a form to pristine state (please note that this is an AngularJS 1.1.x feature).

如果你想要一个 $scope.form.$setPristine()-ish 行为,即使在 AngularJS 的 1.0.x 分支,你需要推出你自己的解决方案(可以找到一些非常好的解决方案此处).基本上,这意味着迭代所有表单字段并将它们的 $dirty 标志设置为 false.

If you want a $scope.form.$setPristine()-ish behavior even in 1.0.x branch of AngularJS, you need to roll your own solution (some pretty good ones can be found here). Basically, this means iterating over all form fields and setting their $dirty flag to false.

希望这会有所帮助.

这篇关于在 AngularJS 中,ng-pristine 和 ng-dirty 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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