In AngularJS, what's the difference between ng-pristine and ng-dirty?

后端 未结 5 1959
臣服心动
臣服心动 2020-12-12 21:53

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

$scope.myForm.$prist         


        
5条回答
  •  离开以前
    2020-12-12 22:02

    As already stated in earlier answers, ng-pristine is for indicating that the field has not been modified, whereas ng-dirty is for telling it has been modified. Why need both?

    Let's say we've got a form with phone and e-mail address among the fields. Either phone or e-mail is required, and you also have to notify the user when they've got invalid data in each field. This can be accomplished by using ng-dirty and ng-pristine together:

    Phone or e-mail required
    E-mail is invalid
    Phone or e-mail required
    Phone is invalid

提交回复
热议问题