Skip to main content

change

Description

fires when a number is changed in the counter

Parameters

  • ev - (object) a CustomEvent object. Its detail property contains:
    • value - (number) the value of the input
    • input - (boolean) true, if a value is being typed (check details)

Example

<script>
function handleChange(ev){
const newValue = ev.detail;
console.log(newValue);
// => {value: 2, input: true}
}
</script>

<Counter value={1} on:change={handleChange}/>

Details

The handler function receives the new value of the counter typed in the input. The received object may also contain input:true, depending on the fired HTML input event:

  • if the input event of the HTML input is caught (a number is being typed), the change event of the Counter control will have input:true in ev.detail
  • if the change event of the HTML input is caught (a user has applied changes), the change event of the Counter control won't have the input property in ev.detail

Related article: Catching the change of the value