填写这份《一分钟调查》,帮我们(开发组)做得更好!去填写Home

DefaultValueAccessor

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.

NgModules

选择器

属性

属性说明
onChange: (_: any) => { }

The registered callback function called when an input event occurs on the input element.

onTouched: () => { }

The registered callback function called when a blur event occurs on the input element.

说明

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();
      
      const firstNameControl = new FormControl();
    
<input type="text" [formControl]="firstNameControl">
      
      <input type="text" [formControl]="firstNameControl">
    

方法

Sets the "value" property on the input element.

writeValue(value: any): void
      
      writeValue(value: any): void
    
参数
value any

The checked value

返回值

void

Registers a function called when the control value changes.

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

The callback function

返回值

void

Registers a function called when the control is touched.

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

The callback function

返回值

void

Sets the "disabled" property on the input element.

setDisabledState(isDisabled: boolean): void
      
      setDisabledState(isDisabled: boolean): void
    
参数
isDisabled boolean

The disabled value

返回值

void