项目作者: mahiwaykos

项目描述 :
Using Currency Pipe inside input Angular 5
高级语言: TypeScript
项目地址: git://github.com/mahiwaykos/currencyPipe.git
创建时间: 2018-01-19T06:26:45Z
项目社区:https://github.com/mahiwaykos/currencyPipe

开源协议:

下载


Angular 5: How to use Currency Pipe inside the input to get formatted currency

Founded the efficient way to use the default currency pipe provided by the angular to format the currecncy while
user is typing the value inside the input.

I had used the Indian currency (INR) in the code. You just need to change currency as per the requirement and also need to update the currency symbol inside the conditions.

For Example we will use for USD:

change INR to USD

  1. this.formattedAmount = this.currencyPipe.transform(this.value, 'USD', true, '1.0-0');

also need to update “₹” sign with the currency symbol in our case replace with “$”

  1. if (element.target.value.indexOf('$') !== -1) {
  2. this.formattedAmount = this.formattedAmount.replace(/[$,]/g, "")