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

angularjs

Solution

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

Problem

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 ```

Original source

Related problems