I want to call the function whenever the input is changed.
I have created the following in my home.html file
<ion-input type="text" class="scoreboardus" [(ngModel)]='text'
(input)='onInputTime($event.target.value)' (change)='onChangeTime($event.target.value)'>
</ion-input>
and in home.ts file
onChangeTime() {
alert('onChangeTime called');
}
onInputTime() {
alert('onInputTime called');
}
the above code works fine if manually give values in the input field.
My problem:
I am changing input value from one of external javascript file.
$('.scoreboardus input').val(200).trigger('onchange');
The above code change the input field value… But function is not called
resultant code should work after creating an app.
By using [(ngModel)]="value" you bind the value variable to that input field. That way it is always updated. If you change it in the UI, it is immediately updated "in the code".
Add an ion input tag with conditional readonly <ion-input [readonly]="isReadonly"> Set isReadonly variable to true. readonly attribute is not rendered on the resulting input tag.
You must use (ionChange) instead of (change).
<ion-input type="text" class="scoreboardus" [(ngModel)]='text' (input)='onInputTime($event.target.value)' (ionChange)='onChangeTime($event.target.value)'>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With