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

后端 未结 5 1973
臣服心动
臣服心动 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:11

    ng-pristine ($pristine)

    Boolean True if the form/input has not been used yet (not modified by the user)

    ng-dirty ($dirty)

    Boolean True if the form/input has been used (modified by the user)


    $setDirty(); Sets the form to a dirty state. This method can be called to add the 'ng-dirty' class and set the form to a dirty state (ng-dirty class). This method will propagate current state to parent forms.

    $setPristine(); Sets the form to its pristine state. This method sets the form's $pristine state to true, the $dirty state to false, removes the ng-dirty class and adds the ng-pristine class. Additionally, it sets the $submitted state to false. This method will also propagate to all the controls contained in this form.

    Setting a form back to a pristine state is often useful when we want to 'reuse' a form after saving or resetting it.

提交回复
热议问题