( control: FormControl, dir: NgControl, callSetDisabledState: SetDisabledStateOption = setDisabledStateDefault, )
| 79 | * @param dir Directive that should be linked with a given control. |
| 80 | */ |
| 81 | export function setUpControlValueAccessor( |
| 82 | control: FormControl, |
| 83 | dir: NgControl, |
| 84 | callSetDisabledState: SetDisabledStateOption = setDisabledStateDefault, |
| 85 | ): void { |
| 86 | if (typeof ngDevMode === 'undefined' || ngDevMode) { |
| 87 | if (!control) _throwError(dir, 'Cannot find control with'); |
| 88 | if (!dir.valueAccessor) _throwMissingValueAccessorError(dir); |
| 89 | } |
| 90 | |
| 91 | setUpValidators(control, dir); |
| 92 | |
| 93 | dir.valueAccessor!.writeValue(control.value); |
| 94 | |
| 95 | // The legacy behavior only calls the CVA's `setDisabledState` if the control is disabled. |
| 96 | // If the `callSetDisabledState` option is set to `always`, then this bug is fixed and |
| 97 | // the method is always called. |
| 98 | if (control.disabled || callSetDisabledState === 'always') { |
| 99 | dir.valueAccessor!.setDisabledState?.(control.disabled); |
| 100 | } |
| 101 | |
| 102 | setUpViewChangePipeline(control, dir); |
| 103 | setUpModelChangePipeline(control, dir); |
| 104 | |
| 105 | setUpBlurPipeline(control, dir); |
| 106 | |
| 107 | setUpDisabledChangeHandler(control, dir); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Reverts configuration performed by the `setUpControl` control function. |
no test coverage detected
searching dependent graphs…