FormBuilder
Creates an AbstractControl
from a user-specified configuration.
class FormBuilder {}
nonNullable
Returns a FormBuilder in which automatically constructed FormControl
elements
have {nonNullable: true}
and are non-nullable.
Constructing non-nullable controls
When constructing a control, it will be non-nullable, and will reset to its initial value.
let nnfb = new FormBuilder().nonNullable;let name = nnfb.control('Alex'); // FormControl<string>name.reset();console.log(name); // 'Alex'
Constructing non-nullable groups or arrays
When constructing a group or array, all automatically created inner controls will be non-nullable, and will reset to their initial values.
let nnfb = new FormBuilder().nonNullable;let name = nnfb.group({who: 'Alex'}); // FormGroup<{who: FormControl<string>}>name.reset();console.log(name); // {who: 'Alex'}
Constructing nullable fields on groups or arrays
It is still possible to have a nullable field. In particular, any FormControl
which is
already constructed will not be altered. For example:
let nnfb = new FormBuilder().nonNullable;// FormGroup<{who: FormControl<string|null>}>let name = nnfb.group({who: new FormControl('Alex')});name.reset(); console.log(name); // {who: null}
Because the inner control is constructed explicitly by the caller, the builder has
no control over how it is created, and cannot exclude the null
.
group
Constructs a new FormGroup
instance. Accepts a single generic argument, which is an object
containing all the keys and corresponding inner control types.
T
A collection of child controls. The key for each child is the name under which it is registered.
AbstractControlOptions | null | undefined
Configuration options object for the FormGroup
. The object should have the
AbstractControlOptions
type and might contain the following fields:
validators
: A synchronous validator function, or an array of validator functions.asyncValidators
: A single async validator or array of async validator functions.updateOn
: The event upon which the control should be updated (options: 'change' | 'blur' | submit').
FormGroup<ɵNullableFormControls<T>>
Constructs a new FormGroup
instance.
{ [key: string]: any; }
A record of child controls. The key for each child is the name under which the control is registered.
{ [key: string]: any; }
Configuration options object for the FormGroup
. The legacy configuration
object consists of:
validator
: A synchronous validator function, or an array of validator functions.asyncValidator
: A single async validator or array of async validator functions Note: the legacy format is deprecated and might be removed in one of the next major versions of Angular.
FormGroup<any>
record
FormRecord<ɵElement<T, null>>
Constructs a new FormRecord
instance. Accepts a single generic argument, which is an object
containing all the keys and corresponding inner control types.
{ [key: string]: T; }
A collection of child controls. The key for each child is the name under which it is registered.
AbstractControlOptions | null
Configuration options object for the FormRecord
. The object should have the
AbstractControlOptions
type and might contain the following fields:
validators
: A synchronous validator function, or an array of validator functions.asyncValidators
: A single async validator or array of async validator functions.updateOn
: The event upon which the control should be updated (options: 'change' | 'blur' | submit').
FormRecord<ɵElement<T, null>>
control
FormControl<T>
FormControl<T>
FormControl<T | null>
FormControl<T | null>
array
FormArray<ɵElement<T, null>>
Constructs a new FormArray
from the given array of configurations,
validators and options. Accepts a single generic argument, which is the type of each control
inside the array.
T[]
An array of child controls or control configs. Each child control is given an index when it is registered.
ValidatorFn | AbstractControlOptions | ValidatorFn[] | null | undefined
A synchronous validator function, or an array of such functions, or an
AbstractControlOptions
object that contains
validation functions and a validation trigger.
AsyncValidatorFn | AsyncValidatorFn[] | null | undefined
A single async validator or array of async validator functions.
FormArray<ɵElement<T, null>>