@dintecom/ngx-currency

中文文档
22.0.0发布于 2026/07/07MITTypeScriptES Module构建来源已验证近 30 天下载 1.5万

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

原始使用文档
文档目录12 节
  1. Demo
  2. Table of contents
  3. Getting Started
  4. Installing and Importing
  5. Using
  6. Options
  7. Development
  8. Prepare your environment
  9. Development server
  10. Building
  11. Testing
  12. License

ngx-currency

npm version GitHub issues GitHub stars GitHub license

Demo

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

Table of contents

Getting Started

Installing and Importing

Install the package by command:

npm install ngx-currency --save

Import the directive

import { NgxCurrency } from "ngx-currency";

@Component({
  selector: "app-root",
  templateUrl: "./app.component.html",
  imports: [NgxCurrency],
})
export class App {}

Using

<input type="text" inputmode="decimal" currencyMask formControlName="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]="{ prefix: 'R$ ', thousands: '.', decimal: ',' }" formControlName="value" />

Available options:

  • align - Text alignment in input. (default: right)
  • allowNegative - If true can input negative values. (default: true)
  • decimal - Separator of decimals (default: '.')
  • precision - Number of decimal places (default: 2)
  • prefix - Money prefix (default: '$ ')
  • suffix - Money suffix (default: '')
  • thousands - Separator of thousands (default: ',')
  • nullable - when true, the value of the clean field will be null, when false the value will be 0
  • min - The minimum value (default: undefined)
  • max - The maximum value (default: undefined)
  • inputMode - Determines how to handle numbers as the user types them (default: Financial)

Input Modes:

  • Financial - Numbers start at the highest precision decimal. Typing a number shifts numbers left. The decimal character is ignored. Most cash registers work this way. For example:
    • Typing '12' results in '0.12'
    • Typing '1234' results in '12.34'
    • Typing '1.234' results in '12.34'
  • Natural - Numbers start to the left of the decimal. Typing a number to the left of the decimal shifts numbers left; typing to the right of the decimal replaces the next number. Most text inputs and spreadsheets work this way. For example:
    • Typing '1234' results in '1234'
    • Typing '1.234' results in '1.23'
    • Typing '12.34' results in '12.34'
    • Typing '123.4' results in '123.40'

You can also set options globally...

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

bootstrapApplication(App, {
  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

  • Install Node.js and NPM
  • Install local dev dependencies: npm install while current directory is this repo

Development server

To start a local development server, run:

npm start

Building

To build the library run:

npm run build:lib

Testing

To execute unit tests with the Vitest test runner, use the following command:

npm test

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

  • From the main Vitest browser page, click the Debug button to open the debug window
  • Press ctrl + shift + i to open Chrome developer tools
  • Press ctrl + p to search for a file to debug
  • Enter a file name like input.handler.ts and click the file
  • Within the file, click on a row number to set a breakpoint
  • Refresh the browser window to re-run tests and stop on the breakpoint

License

MIT @ Neri Bez Fontana

版本与发布记录

@dintecom/ngx-currency 共发布 5 个版本,首次发布于 2025/12/09;过去 12 个月发布了 5 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
22.0.0latest2026/07/074 个月前
21.0.12026/02/208 个月前
20.0.0latest-202026/02/208 个月前
21.0.02025/12/0911 个月前
0.0.02025/12/0911 个月前

关于 @dintecom/ngx-currency 的常见问题

@dintecom/ngx-currency 是什么?

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

如何安装 @dintecom/ngx-currency?

在项目目录运行 npm install @dintecom/ngx-currency,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@angular/common(^22.0.0)、@angular/core(^22.0.0)、@angular/forms(^22.0.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@dintecom/ngx-currency 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@dintecom/ngx-currency 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@dintecom/ngx-currency 可以商用吗?

@dintecom/ngx-currency 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dintecom/ngx-currency 的下载量有多少?

根据 npm 官方下载统计,@dintecom/ngx-currency 在 2026/10/13 – 2026/11/11 这 30 天内被下载 14,950 次,日均约 498 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dintecom/ngx-currency 还在维护吗?

最新版本 22.0.0 发布于 2026/07/07(4 个月前);至今共发布 5 个版本,其中过去 12 个月发布了 5 个;首次发布于 2025/12/09。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。