Writing and Registering Values
Implement writeValue and change callbacks.
Two Core Methods
The heart of a value accessor is moving data both ways: writeValue brings the model value into your view, and the callback from registerOnChange sends user edits back to the model.
writeValue
Angular calls writeValue when the form sets or resets the control's value. Store it in your component state so the view reflects it.
value = 0;
writeValue(value: number): void {
this.value = value ?? 0;
}All lessons in this course
- The ControlValueAccessor Interface
- Writing and Registering Values
- Handling Disabled and Touched States
- Validation in Custom Controls