setUpControl function
Implementation
void setUpControl(Control control, NgControl dir) {
assert(
dir.valueAccessor != null,
'No value accessor for '
'(${dir.path!.join(' -> ')}) or you may be missing formDirectives in '
'your directives list.');
control.validator = Validators.compose([control.validator, dir.validator]);
var valueAccessor = dir.valueAccessor!;
valueAccessor.writeValue(control.value);
// view -> model
valueAccessor.registerOnChange((dynamic newValue, {String? rawValue}) {
dir.viewToModelUpdate(newValue);
control.updateValue(newValue,
emitModelToViewChange: false, rawValue: rawValue);
control.markAsDirty(emitEvent: false);
});
// model -> view
control.registerOnChange(
(dynamic newValue) => dir.valueAccessor?.writeValue(newValue));
control.disabledChanges.listen(valueAccessor.onDisabledChanged);
if (control.disabled) valueAccessor.onDisabledChanged(control.disabled);
// touched
valueAccessor.registerOnTouched(() => control.markAsTouched());
}