3

I am currently learning angularJS and read about ng-pristine and ng-untouched directives for angular forms.

I am having trouble conceptually differentiating between these two directives, to me they seem to be one and the same by their definition.

For reference, here is how angular defines these directives: ng-untouched: the control hasn't been blurred ng-pristine: the control hasn't been interacted with yet

With my logic, I think that an element that is untouched implies that it is an element that is pristine and vice versa. This is mostly because usually the only type of interaction I have programmed with form elements have been blurs.

What are some other types of "interactions" that one could imagine for a form control other than blurring it?

sirlanceoflompoc
  • 941
  • 9
  • 11
  • 1
    possible duplicate of [Angular - difference between pristine/dirty and touched/untouched](http://stackoverflow.com/questions/25025102/angular-difference-between-pristine-dirty-and-touched-untouched) – XML Sep 28 '15 at 14:17

1 Answers1

11

Suppose you have a text field in your form and you navigate through it using your tab key. As soon as you leave the field, it's not untouched anymore. But since you haven't entered or removed any character in the field, it's still pristine. The other types of interaction are the main ones: entering a value, select an option, etc.

JB Nizet
  • 678,734
  • 91
  • 1,224
  • 1,255
  • Ah I think understand. After messing with the code I found that pristine is basically asking, does this form element have user input? If so, then the form control is dirty, otherwise it is pristine. Is that correct? Thanks you for this response. – sirlanceoflompoc Jan 07 '15 at 00:13
  • Not sure about this. I think if your input has an ng-model with a value, then it is still considered pristine. If you change the value, then it is no longer pristine. What has always been odd to me, is that if you change the value, then change it back to what it started at, then it is STILL not pristine--- i'm sure there are many SO posts related to this. – ek_ny Oct 06 '15 at 16:20