MCPcopy Index your code
hub / github.com/angular/angular / cleanUpControl

Function cleanUpControl

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

Source from the content-addressed store, hash-verified

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

Used in the wild real call sites across dependent graphs

searching dependent graphs…