class
final
Tracks the value and validity state of a collection of FormControl
instances, each of which has the same value type.
class FormRecord<TControl extends AbstractControl = AbstractControl, TControl> extends FormGroup<{ [key: string]: TControl; }> { registerControl(name: string, control: TControl): TControl addControl(name: string, control: TControl, options?: { emitEvent?: boolean; }): void removeControl(name: string, options?: { emitEvent?: boolean; }): void setControl(name: string, control: TControl, options?: { emitEvent?: boolean; }): void contains(controlName: string): boolean setValue(value: { [key: string]: ɵValue<TControl>; }, options?: { onlySelf?: boolean; emitEvent?: boolean; }): void patchValue(value: { [key: string]: ɵValue<TControl>; }, options?: { onlySelf?: boolean; emitEvent?: boolean; }): void reset(value?: { [key: string]: ɵValue<TControl>; }, options?: { onlySelf?: boolean; emitEvent?: boolean; }): void getRawValue(): {...} // inherited from forms/FormGroup constructor(controls: TControl, validatorOrOpts?: ValidatorFn | AbstractControlOptions | ValidatorFn[], asyncValidator?: AsyncValidatorFn | AsyncValidatorFn[]) controls: ɵTypedOrUntyped<TControl, TControl, {...} registerControl<K extends string & keyof TControl>(name: K, control: TControl[K]): TControl[K] addControl<K extends string & keyof TControl>(name: K, control: Required<TControl>[K], options: { emitEvent?: boolean; } = {}): void removeControl(name: string, options: { emitEvent?: boolean; } = {}): void setControl<K extends string & keyof TControl>(name: K, control: TControl[K], options: { emitEvent?: boolean; } = {}): void contains<K extends string & keyof TControl>(controlName: K): boolean setValue(value: ɵIsAny<TControl, { [key: string]: any; }, { [K in keyof TControl]: ɵRawValue<TControl[K]>; }>, options: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void patchValue(value: ɵIsAny<TControl, { [key: string]: any; }, Partial<{ [K in keyof TControl]: ɵValue<TControl[K]>; }>>, options: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void reset(value: ɵIsAny<TControl, any, ɵIsAny<TControl, { [key: string]: any; }, Partial<{ [K in keyof TControl]: ɵValue<TControl[K]>; }>>> = {} as unknown as ɵFormGroupValue<TControl>, options: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void getRawValue(): ɵTypedOrUntyped<TControl, ɵFormGroupRawValue<TControl>, any> // inherited from forms/AbstractControl constructor(validators: ValidatorFn | ValidatorFn[], asyncValidators: AsyncValidatorFn | AsyncValidatorFn[]) value: TValue validator: ValidatorFn | null asyncValidator: AsyncValidatorFn | null parent: FormGroup | FormArray | null status: FormControlStatus valid: boolean invalid: boolean pending: boolean disabled: boolean enabled: boolean errors: ValidationErrors | null pristine: boolean dirty: boolean touched: boolean untouched: boolean valueChanges: Observable<TValue> statusChanges: Observable<FormControlStatus> updateOn: FormHooks root: AbstractControl setValidators(validators: ValidatorFn | ValidatorFn[]): void setAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[]): void addValidators(validators: ValidatorFn | ValidatorFn[]): void addAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[]): void removeValidators(validators: ValidatorFn | ValidatorFn[]): void removeAsyncValidators(validators: AsyncValidatorFn | AsyncValidatorFn[]): void hasValidator(validator: ValidatorFn): boolean hasAsyncValidator(validator: AsyncValidatorFn): boolean clearValidators(): void clearAsyncValidators(): void markAsTouched(opts: { onlySelf?: boolean; } = {}): void markAllAsTouched(): void markAsUntouched(opts: { onlySelf?: boolean; } = {}): void markAsDirty(opts: { onlySelf?: boolean; } = {}): void markAsPristine(opts: { onlySelf?: boolean; } = {}): void markAsPending(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void disable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void enable(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void setParent(parent: FormGroup<any> | FormArray<any>): void abstract setValue(value: TRawValue, options?: Object): void abstract patchValue(value: TValue, options?: Object): void abstract reset(value?: TValue, options?: Object): void getRawValue(): any updateValueAndValidity(opts: { onlySelf?: boolean; emitEvent?: boolean; } = {}): void setErrors(errors: ValidationErrors, opts: { emitEvent?: boolean; } = {}): void get<P extends string | ((string | number)[])>(path: P): AbstractControl<ɵGetProperty<TRawValue, P>> | null getError(errorCode: string, path?: string | (string | number)[]): any hasError(errorCode: string, path?: string | (string | number)[]): boolean }
FormRecord
is very similar to FormGroup
, except it can be used with a dynamic keys, with controls added and removed as needed.
FormRecord
accepts one generic argument, which describes the type of the controls it contains.
Further information is available in the Usage Notes...
registerControl() | ||||||
---|---|---|---|---|---|---|
Registers a control with the records's list of controls. | ||||||
|
name | string | |
control | TControl |
TControl
See FormGroup#registerControl
for additional information.
addControl() | |||||||||
---|---|---|---|---|---|---|---|---|---|
Add a control to this group. | |||||||||
|
name | string | |
control | TControl | |
options | object | Optional. Default is |
void
See FormGroup#addControl
for additional information.
removeControl() | ||||||
---|---|---|---|---|---|---|
Remove a control from this group. | ||||||
|
name | string | |
options | object | Optional. Default is |
void
See FormGroup#removeControl
for additional information.
setControl() | |||||||||
---|---|---|---|---|---|---|---|---|---|
Replace an existing control. | |||||||||
|
name | string | |
control | TControl | |
options | object | Optional. Default is |
void
See FormGroup#setControl
for additional information.
contains() | |||
---|---|---|---|
Check whether there is an enabled control with the given name in the group. | |||
|
controlName | string |
boolean
See FormGroup#contains
for additional information.
setValue() | ||||||
---|---|---|---|---|---|---|
Sets the value of the | ||||||
|
value | object | |
options | object | Optional. Default is |
void
See FormGroup#setValue
for additional information.
patchValue() | ||||||
---|---|---|---|---|---|---|
Patches the value of the | ||||||
|
value | object | |
options | object | Optional. Default is |
void
See FormGroup#patchValue
for additional information.
reset() | ||||||
---|---|---|---|---|---|---|
Resets the | ||||||
|
value | object | Optional. Default is |
options | object | Optional. Default is |
void
See FormGroup#reset
for additional information.
getRawValue() |
---|
The aggregate value of the |
|
See |
let numbers = new FormRecord({bill: new FormControl('415-123-456')}); numbers.addControl('bob', new FormControl('415-234-567')); numbers.removeControl('bill');
© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/forms/FormRecord