MCPcopy
hub / github.com/angular/angular / FormField

Class FormField

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

Source from the content-addressed store, hash-verified

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

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…