MCPcopy Create free account
hub / github.com/angular/angular / FormField

Class FormField

packages/forms/signals/src/directive/form_field.ts:117–438  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

115 ],
116})
117export class FormField<T> {
118 /**
119 * The field to bind to the underlying form control.
120 */
121 readonly field = input.required<Field<T>>({alias: 'formField'});
122
123 /**
124 * `FieldState` for the currently bound field.
125 */
126 readonly state = computed<FieldState<T>>(() => this.field()());
127
128 /** @internal */
129 readonly renderer = inject(Renderer2);
130
131 /** @internal */
132 readonly destroyRef = inject(DestroyRef);
133
134 /**
135 * The node injector for the DOM element hosting this field binding.
136 */
137 readonly injector = inject(Injector);
138
139 /**
140 * The DOM element hosting this field binding.
141 */
142 readonly element = inject<ElementRef<HTMLElement>>(ElementRef).nativeElement;
143
144 // Compute some helper booleans about the type of element we're sitting on.
145 private readonly elementIsNativeFormElement = isNativeFormElement(this.element);
146 private readonly elementAcceptsTextualValues = isTextualFormElement(this.element);
147 private _elementAcceptsMinMax: boolean | undefined;
148
149 /**
150 * Utility that casts `this.element` to `NativeFormControl` to avoid repeated type guards. Only
151 * safe to access when `elementIsNativeFormElement` is true.
152 *
153 * @internal
154 */
155 readonly nativeFormElement: NativeFormControl = (this.elementIsNativeFormElement
156 ? this.element
157 : undefined) as NativeFormControl;
158
159 /**
160 * Current focus implementation, set by `registerAsBinding`.
161 */
162 private focuser = (options?: FocusOptions) => this.element.focus(options);
163
164 /** Any `ControlValueAccessor` instances provided on the host element. */
165 private readonly controlValueAccessors = inject(NG_VALUE_ACCESSOR, {optional: true, self: true});
166
167 private readonly config = inject(SIGNAL_FORMS_CONFIG, {optional: true});
168 private readonly validityMonitor = inject(InputValidityMonitor);
169
170 /** @internal */
171 readonly parseErrorsSource = signal<
172 Signal<readonly ValidationError.WithoutFieldTree[]> | undefined
173 >(undefined);
174

Callers

nothing calls this directly

Calls 13

computedFunction · 0.90
injectFunction · 0.90
isNativeFormElementFunction · 0.90
isTextualFormElementFunction · 0.90
signalFunction · 0.90
untrackedFunction · 0.90
mapMethod · 0.80
focusMethod · 0.65
requiredMethod · 0.45
fieldMethod · 0.45
filterMethod · 0.45
errorsMethod · 0.45

Tested by

no test coverage detected