Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is this possible to add a custom onChange function to the default FormControl in Angular2?

Tags:

angular

Is this possible to add a custom onChange function to the default FormControl? Currently I've seen examples on registering onchange functions on a custom input but non on the default FormControl.

like image 309
Daniel Luu Avatar asked Oct 19 '25 17:10

Daniel Luu


1 Answers

It is possible to bind to the change events for FormControls. For input boxes you need to bind to the input event and for dropdown boxes you need to bind to the change event.

<form [formGroup]="form">
    <input  formControlName="inputControl"
          (input)="inputChange()"
          placeholder="Enter a Value"/>
    <select formControlName="dropdownControl"
            (change)="dropdownChange()">
        <option>Beetle</option>
        <option>Lady Bug</option>
        <option>Grasshopper</option>
        <option>Firefly</option>
    </select>
</form>

Here is a Plunkr demonstrating how the events work.

like image 147
Teddy Sterne Avatar answered Oct 22 '25 05:10

Teddy Sterne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!