DefaultValueAccessor

From Get docs
< @angular/formsAngular/docs/11/api/forms/defaultvalueaccessor


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.

See more...

Exported from

Selectors

  • input:not([type=checkbox])[formControlName]
  • textarea[formControlName]
  • input:not([type=checkbox])[formControl]
  • textarea[formControl]
  • input:not([type=checkbox])[ngModel]
  • textarea[ngModel]
  • [ngDefaultControl]

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">

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

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

© 2010–2021 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://v11.angular.io/api/forms/DefaultValueAccessor