DefaultValueAccessor

directive

npm Package @angular/forms
Module import { DefaultValueAccessor } from '@angular/forms';
Source forms/src/directives/default_value_accessor.ts

Overview

@Directive({
    selector: 'input:not([type=checkbox])[formControlName],textarea[formControlName],input:not([type=checkbox])[formControl],textarea[formControl],input:not([type=checkbox])[ngModel],textarea[ngModel],[ngDefaultControl]',
    host: {
        '(input)': '_handleInput($event.target.value)',
        '(blur)': 'onTouched()',
        '(compositionstart)': '_compositionStart()',
        '(compositionend)': '_compositionEnd($event.target.value)'
    },
    providers: [DEFAULT_VALUE_ACCESSOR]
})
class DefaultValueAccessor implements ControlValueAccessor {
  onChange: (_: any) => {}
  onTouched: () => {}
  writeValue(value: any): void
  registerOnChange(fn: (_: any) => void): void
  registerOnTouched(fn: () => void): void
  setDisabledState(isDisabled: boolean): void
}

Selectors

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

Description

The default accessor for writing a value and listening to changes that is used by the NgModel, FormControlDirective, and FormControlName directives.

Example

<input type="text" name="searchQuery" ngModel>

Constructor

constructor(_renderer: Renderer2, _elementRef: ElementRef, _compositionMode: boolean)

Members

onChange: (_: any) => {}

onTouched: () => {}

writeValue(value: any): void

registerOnChange(fn: (_: any) => void): void

registerOnTouched(fn: () => void): void

setDisabledState(isDisabled: boolean): void

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