DefaultValueAccessor
directive
The default ControlValueAccessor for writing a value and listening to changes on input elements. The accessor is used by the FormControlDirective, FormControlName, and NgModel directives.
NgModules
-
ReactiveFormsModule -
FormsModule
Selectors
input:not([type=checkbox])[formControlName]textarea[formControlName]input:not([type=checkbox])[formControl]textarea[formControl]input:not([type=checkbox])[ngModel]textarea[ngModel][ngDefaultControl]
Properties
| Property | Description |
|---|---|
onChange: (_: any) => { }
|
The registered callback function called when an input event occurs on the input element. |
onTouched: () => { }
|
The registered callback function called when a blur event occurs on the input element. |
Description
Using the default value accessor
The following example shows how to use an input element that activates the default value accessor (in this case, a text field).
const firstNameControl = new FormControl();
<input type="text" [formControl]="firstNameControl">
Methods
|
writeValue() | |||
|---|---|---|---|
| Sets the "value" property on the input element. | |||
writeValue(value: any): voidParameters
Returns
|
|
registerOnChange() | |||
|---|---|---|---|
| Registers a function called when the control value changes. | |||
registerOnChange(fn: (_: any) => void): voidParameters
Returns
|
|
registerOnTouched() | |||
|---|---|---|---|
| Registers a function called when the control is touched. | |||
registerOnTouched(fn: () => void): voidParameters
Returns
|
|
setDisabledState() | |||
|---|---|---|---|
| Sets the "disabled" property on the input element. | |||
setDisabledState(isDisabled: boolean): voidParameters
Returns
|
© 2010–2019 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v7.angular.io/api/forms/DefaultValueAccessor