©
本文檔使用 php中文網手册 發布
FormController
keeps track of all its controls and nested forms as well as the state of them,
such as being valid/invalid or dirty/pristine.
Each form directive creates an instance
of FormController
.
$rollbackViewValue();
Rollback all form controls pending updates to the $modelValue
.
Updates may be pending by a debounced event or because the input is waiting for a some future
event defined in ng-model-options
. This method is typically needed by the reset button of
a form that uses ng-model-options
to pend updates.
$commitViewValue();
Commit all form controls pending updates to the $modelValue
.
Updates may be pending by a debounced event or because the input is waiting for a some future
event defined in ng-model-options
. This method is rarely needed as NgModelController
usually handles calling this in response to input events.
$addControl();
Register a control with the form.
Input elements using ngModelController do this automatically when they are linked.
$removeControl();
Deregister a control from the form.
Input elements using ngModelController do this automatically when they are destroyed.
$setValidity();
Sets the validity of a form control.
This method will also propagate to parent forms.
$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 also propagate to parent forms.
$setPristine();
Sets the form to its pristine state.
This method can be called to remove the 'ng-dirty' class and set the form to its pristine state (ng-pristine class). 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.
$pristine
boolean |
True if user has not interacted with the form yet. |
$dirty
boolean |
True if user has already interacted with the form. |
$valid
boolean |
True if all of the containing forms and controls are valid. |
$invalid
boolean |
True if at least one containing control or form is invalid. |
$error
Object |
Is an object hash, containing references to all invalid controls or forms, where:
Built-in validation tokens:
|