Does someone know why this code doesn’t work? And what would be the correct way to do that?
<ion-input type="number" (ngModel)="table.price" [ngModel]="table.price.toFixed(2)"></ion-input>
The table.price is inserted into ion-input after load, but if I change the value, the table.price doesn’t receive the ion-input typed.
Thanks!
The convention is (ngModelChange)
in this situation, not (ngModel)
.
Leaving aside the fact that you should never be putting function calls in [ngModel]
(because change detection can’t tell they’re stable), the following does what I would expect in a scratch project:
<ion-item>
<ion-input [ngModel]="fruit" (ngModelChange)="onFruitChange($event)"></ion-input>
</ion-item>
onFruitChange(fruit: string) {
console.log("fruit changed " + fruit);
}