在AngularJS,什么是NG-原始和NG-脏之间的区别? [英] In AngularJS, what's the difference between ng-pristine and ng-dirty?

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

问题描述

什么是之间的差别NG-质朴 NG-脏?看来你可以同时为真正

  $ scope.myForm $质朴= TRUE; //编辑表单后,


解决方案

NG-脏类告诉您该表已被用户修改,而 NG-质朴类告诉你的形式没有被用户修改。因此, NG-脏 NG-质朴都是同一个故事的两个方面。

的类设置任​​何字段,而形式有两个属性, $脏 $质朴

您可以使用 $ scope.form。$ setPristine()功能重置形式原始状态(请注意,这是一个AngularJS 1.1.x的功能)

如果你想,即使在AngularJS的1.0.x的分支 $ scope.form。$ setPristine() -ish行为,您需要推出自己的解决方案(有些pretty好的,可以发现 <一个href=\"http://stackoverflow.com/questions/12603914/reset-form-to-pristine-state-angularjs-1-0-x\">here).基本上,这意味着在迭代所有的表单字段及其 $脏标志设置为

希望这有助于。

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

解决方案

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.

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

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).

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.

Hope this helps.

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

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