Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic:Change event is not fired on <ion-input> when the input value is changed from external script

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.

like image 503
Sugumar Venkatesan Avatar asked Sep 08 '17 06:09

Sugumar Venkatesan


People also ask

How do you assign a value to an input field in ionic?

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".

How do you make ion input readonly?

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.


1 Answers

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)'>
like image 194
Fabio Campinho Avatar answered Sep 22 '22 09:09

Fabio Campinho