# Class FormController

- Defined in directive/form/form.js:91
- Defined in directive/form/form.js:84
- Defined in directive/form/form.js:119

#####
Index

### Constructors

constructor

### Properties

$$animate
$$controls
$$element
$$parentForm
$$success
$dirty
$error
$invalid
$name
$pending
$pristine
$submitted
$valid
$inject
prototype

### Methods

$$renameControl
$$setSubmitted
$addControl
$commitViewValue
$getControls
$removeControl
$rollbackViewValue
$setDirty
$setPristine
$setSubmitted
$setUntouched

##
Constructors

### constructor

- new FormController($element, $attrs, $scope, $animate, $interpolate): FormController

- #### Parameters

  - $element: any
  - $attrs: any
  - $scope: any
  - $animate: any
  - $interpolate: any

  #### Returns FormController

  - Defined in directive/form/form.js:91

##
Properties

### $$animate

$$animate: any

- Defined in directive/form/form.js:114

### $$controls

$$controls: any[]

- Defined in directive/form/form.js:98

### $$element

$$element: any

- Defined in directive/form/form.js:113

### $$parentForm

$$parentForm: any

- Defined in directive/form/form.js:111

### $$success

$$success: {}

- Defined in directive/form/form.js:102

### $dirty

$dirty: boolean

- Defined in directive/form/form.js:105
- Defined in directive/form/form.js:253
- Defined in directive/form/form.js:276

### $error

$error: {}

- Defined in directive/form/form.js:101

### $invalid

$invalid: boolean

- Defined in directive/form/form.js:108

### $name

$name: any

- Defined in directive/form/form.js:104

### $pending

$pending: any

- Defined in directive/form/form.js:103

### $pristine

$pristine: boolean

- Defined in directive/form/form.js:106
- Defined in directive/form/form.js:254
- Defined in directive/form/form.js:277

### $submitted

$submitted: boolean

- Defined in directive/form/form.js:109
- Defined in directive/form/form.js:278
- Defined in directive/form/form.js:314

### $valid

$valid: boolean

- Defined in directive/form/form.js:107

### `Static`$inject

$inject: string[]

#### Description

`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 ng.directive:form form directive creates an instance of `FormController`.

- Defined in directive/form/form.js:84

### `Static` prototype

prototype: {
$$renameControl(control: any, newName: any): void;
$$setSubmitted(): void;
$addControl(control: any): void;
$commitViewValue(): void;
$getControls(): any;
$removeControl(control: any): void;
$rollbackViewValue(): void;
$setDirty(): void;
$setPristine(): void;
$setSubmitted(): void;
$setUntouched(): void;
}

#### Type declaration

- ##### $$renameControl:function

  - $$renameControl(control, newName): void

  - #### Parameters

    - control: any
    - newName: any

    #### Returns void

    - Defined in directive/form/form.js:194

- ##### $$setSubmitted:function

  - $$setSubmitted(): void

  - #### Returns void

    - Defined in directive/form/form.js:312

- ##### $addControl:function

  - $addControl(control): void

  - Register a control with the form. Input elements using ngModelController do this automatically when they are linked.

    Note that the current state of the control will not be reflected on the new parent form. This is not an issue with normal use, as freshly compiled and linked controls are in a `$pristine` state.

    However, if the method is used programmatically, for example by adding dynamically created controls, or controls that have been previously removed without destroying their corresponding DOM element, it's the developers responsibility to make sure the current state propagates to the parent form.

    For example, if an input control is added that is already `$dirty` and has `$error` properties, calling `$setDirty()` and `$validate()` afterwards will propagate the state to the parent form.

    #### Parameters

    - control: any

    #### Returns void

    - Defined in directive/form/form.js:161

- ##### $commitViewValue:function

  - $commitViewValue(): void

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

    #### Returns void

    - Defined in directive/form/form.js:140

- ##### $getControls:function

  - $getControls(): any

  - This method returns a shallow copy of the controls that are currently part of this form. The controls can be instances of form.FormController `FormController` (ngForm "child-forms") and of ngModel.NgModelController `NgModelController`. If you need access to the controls of child-forms, you have to call `$getControls()` recursively on them. This can be used for example to iterate over all controls to validate them.

    The controls can be accessed normally, but adding to, or removing controls from the array has no effect on the form. Instead, use form.FormController#$addControl `$addControl()` and form.FormController#$removeControl `$removeControl()` for this use-case. Likewise, adding a control to, or removing a control from the form is not reflected in the shallow copy. That means you should get a fresh copy from `$getControls()` every time you need access to the controls.

    #### Returns any

    - Defined in directive/form/form.js:189

- ##### $removeControl:function

  - $removeControl(control): void

  - Deregister a control from the form.

    Input elements using ngModelController do this automatically when they are destroyed.

    Note that only the removed control's validation state (`$errors`etc.) will be removed from the form. `$dirty`, `$submitted` states will not be changed, because the expected behavior can be different from case to case. For example, removing the only `$dirty` control from a form may or may not mean that the form is still `$dirty`.

    #### Parameters

    - control: any

    #### Returns void

    - Defined in directive/form/form.js:214

- ##### $rollbackViewValue:function

  - $rollbackViewValue(): void

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

    #### Returns void

    - Defined in directive/form/form.js:127

- ##### $setDirty:function

  - $setDirty(): void

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

    #### Returns void

    - Defined in directive/form/form.js:250

- ##### $setPristine:function

  - $setPristine(): void

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

    #### Returns void

    - Defined in directive/form/form.js:270

- ##### $setSubmitted:function

  - $setSubmitted(): void

  - Sets the form to its `$submitted` state. This will also set `$submitted` on all child and parent forms of the form.

    #### Returns void

    - Defined in directive/form/form.js:303

- ##### $setUntouched:function

  - $setUntouched(): void

  - Sets the form to its untouched state.

    This method can be called to remove the 'ng-touched' class and set the form controls to their untouched state (ng-untouched class).

    Setting a form controls back to their untouched state is often useful when setting the form back to its pristine state.

    #### Returns void

    - Defined in directive/form/form.js:293

- Defined in directive/form/form.js:119

##
Methods

### $$renameControl

- $$renameControl(control, newName): void

- #### Parameters

  - control: any
  - newName: any

  #### Returns void

  - Defined in directive/form/form.js:194

### $$setSubmitted

- $$setSubmitted(): void

- #### Returns void

  - Defined in directive/form/form.js:312

### $addControl

- $addControl(control): void

- Register a control with the form. Input elements using ngModelController do this automatically when they are linked.

  Note that the current state of the control will not be reflected on the new parent form. This is not an issue with normal use, as freshly compiled and linked controls are in a `$pristine` state.

  However, if the method is used programmatically, for example by adding dynamically created controls, or controls that have been previously removed without destroying their corresponding DOM element, it's the developers responsibility to make sure the current state propagates to the parent form.

  For example, if an input control is added that is already `$dirty` and has `$error` properties, calling `$setDirty()` and `$validate()` afterwards will propagate the state to the parent form.

  #### Parameters

  - control: any

  #### Returns void

  - Defined in directive/form/form.js:161

### $commitViewValue

- $commitViewValue(): void

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

  #### Returns void

  - Defined in directive/form/form.js:140

### $getControls

- $getControls(): any

- This method returns a shallow copy of the controls that are currently part of this form. The controls can be instances of form.FormController `FormController` (ngForm "child-forms") and of ngModel.NgModelController `NgModelController`. If you need access to the controls of child-forms, you have to call `$getControls()` recursively on them. This can be used for example to iterate over all controls to validate them.

  The controls can be accessed normally, but adding to, or removing controls from the array has no effect on the form. Instead, use form.FormController#$addControl `$addControl()` and form.FormController#$removeControl `$removeControl()` for this use-case. Likewise, adding a control to, or removing a control from the form is not reflected in the shallow copy. That means you should get a fresh copy from `$getControls()` every time you need access to the controls.

  #### Returns any

  - Defined in directive/form/form.js:189

### $removeControl

- $removeControl(control): void

- Deregister a control from the form.

  Input elements using ngModelController do this automatically when they are destroyed.

  Note that only the removed control's validation state (`$errors`etc.) will be removed from the form. `$dirty`, `$submitted` states will not be changed, because the expected behavior can be different from case to case. For example, removing the only `$dirty` control from a form may or may not mean that the form is still `$dirty`.

  #### Parameters

  - control: any

  #### Returns void

  - Defined in directive/form/form.js:214

### $rollbackViewValue

- $rollbackViewValue(): void

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

  #### Returns void

  - Defined in directive/form/form.js:127

### $setDirty

- $setDirty(): void

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

  #### Returns void

  - Defined in directive/form/form.js:250

### $setPristine

- $setPristine(): void

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

  #### Returns void

  - Defined in directive/form/form.js:270

### $setSubmitted

- $setSubmitted(): void

- Sets the form to its `$submitted` state. This will also set `$submitted` on all child and parent forms of the form.

  #### Returns void

  - Defined in directive/form/form.js:303

### $setUntouched

- $setUntouched(): void

- Sets the form to its untouched state.

  This method can be called to remove the 'ng-touched' class and set the form controls to their untouched state (ng-untouched class).

  Setting a form controls back to their untouched state is often useful when setting the form back to its pristine state.

  #### Returns void

  - Defined in directive/form/form.js:293