Reputation: 364
I have two inputs, the first called before, and second called after
when i introduce a value in before
the after
value will be
before / 1000
witch it means 3 decimals or more sometimes
How should i display the after
input value with 2 decimals only? without changing its decimal value and precicision
Is there any #HTML #JS or #Angular tip
I tried to use pipes, but they aren't allowed in ngModel directives
<ion-label for="ristourneAmount">Source: </ion-label>
<ion-input
type="number"
step="0.01" [(ngModel)]="before"
(change)="onChange()">
</ion-input>
<ion-label for="ristourneAmount">Destination: </ion-label>
<ion-input
type="number"
step="0.01" [(ngModel)]="after">
</ion-input>
Upvotes: 1
Views: 420
Reputation: 1499
<ion-input
type="number"
step="0.01"(change)="setTwoNumberDecimal($event)"
(ngModelChange)="item.value=$event"
[[ngModelOptions]="{updateOn: 'blur'}"
[ngModel]="after">
</ion-input>
Rather than using two way binding you can use single way binding and tap on the events of blur and change on the event declare the function in angular which should be doing the following
setTwoNumberDecimal(event:any){
let value=event.value;
event.value=value.toFixed(2);
}
Upvotes: 1