DefaultValueAccessor

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

@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)': '$any(this)._handleInput($event.target.value)', '(blur)': 'onTouched()', '(compositionstart)': '$any(this)._compositionStart()', '(compositionend)': '$any(this)._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 }

选择器

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

说明

Example

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

属性

属性名类型说明
onChange
onTouched

方法

writeValue(value: any): void

参数

value

Type: any.

返回值

void

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

参数

fn

Type: (_: any) => void.

返回值

void

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

参数

fn

Type: () => void.

返回值

void

setDisabledState(isDisabled: boolean): void

参数

isDisabled

Type: boolean.

返回值

void