This directive validates monetary inputs in "42.53" format (some additional work is needed for "32,00" European formats). Note that this is not designed to work with currency symbols. It largely behaves like Angular's implementation of type="number"
.
It does a few things:
- Prevents entering non-numeric characters
- Prevents entering the minus sign when
min >= 0
- Supports
min
andmax
like in<input type="number">
- Rounds the model value by
precision
, e.g.42.219
will be rounded to42.22
by default - On
blur
, the input field is auto-formatted. Say if you enter42
, it will be formatted to42.00
$ bower install angular-money-directive
Then include it as a dependency in your app.
angular.module('myApp', ['fiestah.money'])
money
: requiredng-model
: requiredtype
: Set totext
or just leave it out. Do not set tonumber
.min
: optional Defaults to0
.max
: optional Not enforced by defaultprecision
: optional Defaults to2
. Set to-1
to disable rounding
Basic example:
<input type="text" ng-model="model.price" money>
min
, max
and precision
can be set dynamically in $scope:
<input type="text" ng-model="model.price" money min="{{min}}">
- Install test deps:
npm install
andbower install
- Run:
./node_modules/karma/bin/karma start