{ "id": "api/forms/DefaultValueAccessor", "title": "DefaultValueAccessor", "contents": "\n\n
\n
\n
\n \n API > @angular/forms\n
\n \n
\n \n
\n

DefaultValueAccessorlink

\n \n \n \n \n \n
\n \n \n\n
\n \n
\n

The default ControlValueAccessor for writing a value and listening to changes on input\nelements. The accessor is used by the FormControlDirective, FormControlName, and\nNgModel directives.

\n\n

See more...

\n
\n \n \n \n \n\n

NgModuleslink

\n\n\n\n \n
\n

Selectorslink

\n \n \n \n
\n\n\n\n \n\n\n\n\n\n \n\n\n \n
\n

Descriptionlink

\n \n\n

Using the default value accessorlink

\n

The following example shows how to use an input element that activates the default value accessor\n(in this case, a text field).

\n\nconst firstNameControl = new FormControl();\n\n\n<input type=\"text\" [formControl]=\"firstNameControl\">\n\n

This value accessor is used by default for <input type=\"text\"> and <textarea> elements, but\nyou could also use it for custom components that have similar behavior and do not require special\nprocessing. In order to attach the default value accessor to a custom element, add the\nngDefaultControl attribute as shown below.

\n\n<custom-input-component ngDefaultControl [(ngModel)]=\"value\"></custom-input-component>\n\n\n
\n \n\n \n\n \n\n \n\n \n \n \n\n
\n
\n\n\n" }