Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS - difference between pristine/dirty and touched/untouched

Tags:

angularjs

AngularJS Developer Guide - Forms lists many styles and directives regarding forms and fields. For each one, a CSS class:

ng-valid ng-invalid ng-pristine ng-dirty ng-touched ng-untouched 

What's the difference between pristine/dirty, and touched/untouched?

like image 865
Luis Masuelli Avatar asked Jul 29 '14 21:07

Luis Masuelli


People also ask

What is the difference between touched and dirty?

The difference between touched and dirty is that with touched the user doesn't need to actually change the value of the input control. touched is true of the field has been touched by the user, otherwise it's false. The opposite of touched is the property untouched .

What is the difference between Ng-dirty and Ng-pristine in angular?

The main difference between both of them is that ng-dirty is used to tell that the input field is modified by the user and the ng-pristine is used to tell us that the field is untouched by the user.

What does pristine mean in angular?

ng-pristine The field has not been modified yet. ng-dirty The field has been modified. ng-valid The field content is valid. ng-invalid The field content is not valid. ng-valid-key One key for each validation.

What does dirty mean in angular?

When the user changes the value in the watched field, the control is marked as "dirty" When the user blurs the form control element, the control is marked as "touched"


1 Answers

AngularJS Developer Guide - CSS classes used by AngularJS

  • @property {boolean} $untouched True if control has not lost focus yet.
  • @property {boolean} $touched True if control has lost focus.
  • @property {boolean} $pristine True if user has not interacted with the control yet.
  • @property {boolean} $dirty True if user has already interacted with the control.
like image 177
Yuriy Rozhovetskiy Avatar answered Oct 31 '22 12:10

Yuriy Rozhovetskiy