Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular2 - Uncaught ReferenceError: onInputChange is not defined at HTMLInputElement.onchange

Uncaught ReferenceError: onInputChange is not defined at HTMLInputElement.onchange

I am looking at the code...,my lord the function exists. And yet I get the above? WOW..why? I just want to fire an event if html changes in input

<input mdInput [formControlName]="i" onchange="onInputChange()"
onInputChange(){

    console.log('DUDE');
}
like image 416
Tampa Avatar asked Mar 01 '26 11:03

Tampa


2 Answers

Binding to the event

<input mdInput [formControlName]="i" (change)="onInputChange()"
like image 58
Roman C Avatar answered Mar 03 '26 00:03

Roman C


Try this:

<input mdInput [formControlName]="i" (change)="onInputChange()"

onInputChange(){

    console.log('DUDE');
}

Also, as its seems you are using model driven form, you can also do that :

this.yourForm.get('i').valueChanges
    .subscribe(data => {
       console.log(data);
    })
like image 41
mickdev Avatar answered Mar 03 '26 01:03

mickdev



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!