A very simple currency mask directive for Angular. You should use the version 7.x.x for Angular 7.x.x.
Note: This component is NOT ready to AoC (Ahead-of-Time) compilation.
Install the package by command:
npm install ng2-money-mask --save
Import the module
import {MoneyMaskModule} from 'ng2-money-mask';
@NgModule({
declarations: [...],
imports: [
//... you others modules
MoneyMaskModule
],
providers: [...]
})
export class AppModule {}
<input [(ngModel)]="moneyText" [(moneyModel)]="moneyValue" mask-money />
ngModel
will get/set the value with text (example:'$ 1,234.56'
) ;moneyModel
will get/set the number value (example:1234.56
);
You can set options...
<!-- example for pt-BR money -->
<input [(ngModel)]="moneyText" [(moneyModel)]="moneyValue" [money-mask-options]="{ prefix: 'R$ ', thousands: '.', decimal: ',' }" mask-money />
Available options:
allowNegative
- Iftrue
can input negative values. (default:false
)precision
- Number of decimal places (default:2
)thousands
- Separator of thousands (default:','
)decimal
- Separator of decimals (default:'.'
)prefix
- Money preffix (is included in ngModel) (default:'$ '
)suffix
- Money suffix (is included in ngModel) (default:''
)