I have an HTML input:
I want to format its value and use an existi
Here is what worked just fine with currency pipe:
<input
matInput
type="text"
placeholder="Test Price"
[ngModel]="testPrice | currency:'USD':'symbol':'2.2'"
[ngModelOptions]="{updateOn:'blur'}"
(ngModelChange)="testPrice=$event"
/>
Basically using the ngModelOptions to update on blur allows for the 0s not to be added while typing in the input field.
I think this is a solution for you:
<input type="text"
[ngModel]="item.value | currency:'USD':true"
(ngModelChange)="item.value=currencyInputChanged($event)">
And then in your controller. Currency mark in from value in input:
currencyInputChanged(value) {
var num = value.replace(/[$,]/g, "");
return Number(num);
}