nbfontana / ngx-currency

Currency mask module for Angular 📦
https://nbfontana.github.io/ngx-currency
MIT License
236 stars 123 forks source link
angular angular2 aot chrome components currency directive firefox mask money

ngx-currency

Build Status npm version GitHub issues GitHub stars GitHub license

Demo

https://nbfontana.github.io/ngx-currency/

Table of contents

About

Getting Started

Installing and Importing

Install the package by command:

    npm install ngx-currency --save

Import the directive

import { NgxCurrencyDirective } from "ngx-currency";

@Component({
  standalone: true,
  selector: "app-root",
  templateUrl: "./app.component.html",
  imports: [NgxCurrencyDirective],
})
export class AppComponent {}

Using

<input type="tel" currencyMask formControlName="value" />

Options

You can set options...

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

Available options:

Input Modes:

You can also set options globally...

import { provideEnvironmentNgxCurrency, NgxCurrencyInputMode } from 'ngx-currency';

bootstrapApplication(AppComponent, {
  providers: [
    ...
    provideEnvironmentNgxCurrency({
      align: "right",
      allowNegative: true,
      allowZero: true,
      decimal: ",",
      precision: 2,
      prefix: "R$ ",
      suffix: "",
      thousands: ".",
      nullable: true,
      min: null,
      max: null,
      inputMode: NgxCurrencyInputMode.Financial,
    }),
    ...
  ],
}).catch((err) => console.error(err));

Development

Prepare your environment

Development server

Run npm start to start a development server.

Testing

When running in the Chrome browser, you can set code breakpoints to debug tests using these instructions:

License

MIT @ Neri Bez Fontana