( control: FormControl | null, dir: NgControl, validateControlPresenceOnChange: boolean = true, )
| 119 | * to avoid potentially breaking changes caused by better control cleanup introduced in #39235. |
| 120 | */ |
| 121 | export 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 | |
| 149 | function registerOnValidatorChange<V>(validators: (V | Validator)[], onChange: () => void): void { |
| 150 | validators.forEach((validator: V | Validator) => { |
no test coverage detected
searching dependent graphs…