I have a user form that takes a input value that is being converted to currency using Angular's currency pipe. Please view the snippet of code below.
app.component.html
<input type="text" [(ngModel)]="value" (blur)="transformAmount($event)" (focus)="transformAmount($event)" required pattern="[0-9]+" class="form-control" id="saleAmount" formControlName="SaleAmount">
app.component.ts
export class QuoteInformationComponent implements OnInit {
formattedAmount: string = '0';
value: any;
transformAmount(element) {
try {
if (typeof (element.target.value) !== 'number')
this.formattedAmount = this.currencyPipe.transform(this.value, 'USD', true, '1.2-2');
element.target.value = this.formattedAmount;
} catch (e) {
console.log(e);
}
}
}
When user is inputting the values, it does the expected behavior of changing the numeric value into a currency amount. But when I reload the project, instead of the currency value showing. It is showing as an integer.
Is there a way to run this method onload or when the input form value is populated?
I am still learning back end development and quite new to angular 4.
Any help is greatly appreciated thank you!