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 }说明
Example
<input type="text" name="searchQuery" ngModel>属性
属性名 | 类型 | 说明 |
---|
onChange | | |
onTouched | | |
方法
|
---|
writeValue(value: any): void参数返回值void
|
|
---|
registerOnChange(fn: (_: any) => void): void参数fn | Type: (_: any) => void . |
返回值void
|
|
---|
registerOnTouched(fn: () => void): void参数返回值void
|
|
---|
setDisabledState(isDisabled: boolean): void参数返回值void
|