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

Function setUpControlValueAccessor

packages/forms/src/directives/shared.ts:82–109  ·  view source on GitHub ↗
(
  control: FormControl,
  dir: NgControl,
  callSetDisabledState: SetDisabledStateOption = setDisabledStateDefault,
)

Source from the content-addressed store, hash-verified

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

Callers 4

_setUpStandaloneMethod · 0.90
_setupWithFormMethod · 0.90
_setupWithFormMethod · 0.90
ngOnChangesMethod · 0.90

Calls 9

_throwErrorFunction · 0.85
setUpValidatorsFunction · 0.85
setUpViewChangePipelineFunction · 0.85
setUpModelChangePipelineFunction · 0.85
setUpBlurPipelineFunction · 0.85
writeValueMethod · 0.65
setDisabledStateMethod · 0.65

Tested by

no test coverage detected