This is one of the three fundamental building blocks of Angular forms, along with
FormGroup and FormArray. It extends the AbstractControl class that
implements most of the base functionality for accessing the value, validation status,
user interactions and events.
A synchronous validator function, or an array of
such functions, or an AbstractControlOptions object that contains validation functions
and a validation trigger.
Configuration options that determine how the control propagates changes
and emits events when the value changes.
The configuration options are passed to the updateValueAndValidity method.
onlySelf: When true, each change only affects this control, and not its parent. Default is
false.
emitEvent: When true or not supplied (the default), both the statusChanges and
valueChanges
observables emit events with the latest status and value when the control value is updated.
When false, no events are emitted.
emitModelToViewChange: When true or not supplied (the default), each change triggers an
onChange event to
update the view.
emitViewToModelChange: When true or not supplied (the default), each change triggers an
ngModelChange
event to update the model.
This function is functionally the same as setValue at this level.
It exists for symmetry with patchValue on FormGroups and
FormArrays, where it does behave differently.
reset(formState: any =null, options:{ onlySelf?: boolean; emitEvent?: boolean;}={}):void
Parameters
formState
any
Resets the control with an initial value,
or an object that defines the initial value and disabled state.
Optional. Default is null.
options
object
Configuration options that determine how the control propagates changes
and emits events after the value changes.
onlySelf: When true, each change only affects this control, and not its parent. Default is
false.
emitEvent: When true or not supplied (the default), both the statusChanges and
valueChanges
observables emit events with the latest status and value when the control is reset.
When false, no events are emitted.
Set the updateOn option to 'blur' to update on the blur event.
const control = new FormControl('', { updateOn: 'blur' });
const control =newFormControl('',{ updateOn:'blur'});
Configure the control to update on a submit event
Set the updateOn option to 'submit' to update on a submit event.
const control = new FormControl('', { updateOn: 'submit' });
const control =newFormControl('',{ updateOn:'submit'});
Reset the control back to an initial value
You reset to a specific form state by passing through a standalone
value or a form state object that contains both a value and a disabled state
(these are the only two properties that cannot be calculated).
const control = new FormControl('Nancy');
console.log(control.value); // 'Nancy'
control.reset('Drew');
console.log(control.value); // 'Drew'
const control =newFormControl('Nancy');
console.log(control.value);// 'Nancy'
control.reset('Drew');
console.log(control.value);// 'Drew'
Reset the control back to an initial value and disabled