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

Function cleanUpControl

packages/forms/src/directives/shared.ts:122–148  ·  view source on GitHub ↗
(
  control: FormControl | null,
  dir: NgControl,
  validateControlPresenceOnChange: boolean = true,
)

Source from the content-addressed store, hash-verified

120 * to avoid potentially breaking changes caused by better control cleanup introduced in #39235.
121 */
122export function cleanUpControl(
123 control: FormControl | null,
124 dir: NgControl,
125 validateControlPresenceOnChange: boolean = true,
126): void {
127 const noop = () => {
128 if (validateControlPresenceOnChange && (typeof ngDevMode === 'undefined' || ngDevMode)) {
129 _noControlError(dir);
130 }
131 };
132
133 // The `valueAccessor` field is typically defined on FromControl and FormControlName directive
134 // instances and there is a logic in `selectValueAccessor` function that throws if it's not the
135 // case. We still check the presence of `valueAccessor` before invoking its methods to make sure
136 // that cleanup works correctly if app code or tests are setup to ignore the error thrown from
137 // `selectValueAccessor`. See https://github.com/angular/angular/issues/40521.
138
139 dir?.valueAccessor?.registerOnChange(noop);
140 dir?.valueAccessor?.registerOnTouched(noop);
141
142 cleanUpValidators(control, dir);
143
144 if (control) {
145 dir._invokeOnDestroyCallbacks();
146 control._registerOnCollectionChange(() => {});
147 }
148}
149
150function registerOnValidatorChange<V>(validators: (V | Validator)[], onChange: () => void): void {
151 validators.forEach((validator: V | Validator) => {

Callers 4

removeControlFunction · 0.90
_updateDomValueFunction · 0.90
ngOnChangesMethod · 0.90
ngOnDestroyMethod · 0.90

Calls 3

cleanUpValidatorsFunction · 0.85
registerOnChangeMethod · 0.65
registerOnTouchedMethod · 0.65

Tested by

no test coverage detected