Skip to content

A very simple currency mask directive that allows using a number attribute with the ngModel.

Notifications You must be signed in to change notification settings

LoveMondays/ng2-currency-mask

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ng2-currency-mask Directive

A very simple currency mask directive for Angular 2 that allows using a number attribute with the ngModel. In other words, the model is a number, and not a string with a mask. It is compatible with Angular 2 2.0.0 and newer. Inspired by https://github.com/castrolol/ng2-mask-money.

Getting Started

Installing and Importing

Install the package by command:

    npm install ng2-currency-mask --save

Import the module

import { CurrencyMaskModule } from "ng2-currency-mask";

@NgModule({
    imports: [
        //... you others modules
        CurrencyMaskModule
    ],
    declarations: [...],
    providers: [...]
})
export class AppModule {}

Using

    <input currencyMask [(ngModel)]="value" />
  • ngModel An attribute of type number. If is displayed '$ 25.63', the attribute will be '25.63'.

Options

You can set options...

    <!-- example for pt-BR money -->
    <input currencyMask [(ngModel)]="value" [options]="{ prefix: 'R$ ', thousands: '.', decimal: ',' }"/>

Available options:

  • allowNegative - If true can input negative values. (default: true)
  • precision - Number of decimal places (default: 2)
  • thousands - Separator of thousands (default: ',')
  • decimal - Separator of decimals (default: '.')
  • prefix - Money preffix (default: '$ ')

Questions? Open a Issue!

About

A very simple currency mask directive that allows using a number attribute with the ngModel.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • TypeScript 100.0%