Help Angular by taking a 1 minute survey!Go to surveyHome

NumberValueAccessor

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

NgModules

Selectors

Properties

Property Description
onChange: (_: any) => { }

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

onTouched: () => { }

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

Description

Using a number input with a reactive form.

The following example shows how to use a number input with a reactive form.

const totalCountControl = new FormControl();
      
      const totalCountControl = new FormControl();
    
<input type="number" [formControl]="totalCountControl">
      
      <input type="number" [formControl]="totalCountControl">
    

Methods

Sets the "value" property on the input element.

writeValue(value: number): void
      
      writeValue(value: number): void
    
Parameters
value number

The checked value

Returns

void

Registers a function called when the control value changes.

registerOnChange(fn: (_: number) => void): void
      
      registerOnChange(fn: (_: number) => void): void
    
Parameters
fn (_: number) => void

The callback function

Returns

void

Registers a function called when the control is touched.

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

The callback function

Returns

void

Sets the "disabled" property on the input element.

setDisabledState(isDisabled: boolean): void
      
      setDisabledState(isDisabled: boolean): void
    
Parameters
isDisabled boolean

The disabled value

Returns

void