I have a TypeScript object to store values as follows.
export class MyObject {
amount: number;
constructor(amount: number) {
this.amount = amount;
}
}
My ionic form (HTML) looks like the following.
<ion-content padding>
<ion-list>
<ion-item>
<ion-label stacked>amount</ion-label>
<ion-input type="number" [(ngModel)]="myObject.amount"></ion-input>
</ion-item>
<ion-item>
<button ion-button (click)="debug()">go</button>
</ion-item>
</ion-list>
</ion-content>
My page backing code looks like the following (without imports and decorators).
export class HomePage {
myObject: MyObject;
constructor(public navCtrl: NavController) {
this.myObject = new MyObject(33.33);
}
debug() {
console.log(this.myObject);
}
}
When I modify the amount value and hit the "go" button and observe the JavaScript console, I notice that the myObject.amount
field value is a string instead of a number.
{ "amount": "20" }
Instead, I should see the following.
{ "amount": 20 }
Any ideas on how to fix this problem?