anubis
anubis

Reputation: 1505

how to actualise a variable in template?

I have a ion-input with a ngModel. I am trying to print the value of the input with (input) event, but, the variable doesn't print the new value immediately. It prints the value when I press some other part of the screen. Do you have any idea of why?

 <ion-input type="number" (input)="change()" [(ngModel)]="value"></ion-input>

{{value}}

EDIT:

value: any;

constructor(public navCtrl: NavController) {}

change() {
    console.log('change ' + this.value);
}

Upvotes: 0

Views: 120

Answers (1)

Gabriel Barreto
Gabriel Barreto

Reputation: 6421

You don't need a change function, just need the ngModel

<ion-input type="number" [(ngModel)]="value"></ion-input>

{{value}}

with this alone you'be able to update the value variable

Upvotes: 1

Related Questions