ngCurrency is a directive that enables seamless use of currency inputs.
Main features:
- The model is consistent as it values is a float (even if there are alpha caracters in the middle) or NaN in the empty case.
- Input value is always filtered with locale currency when load and on blur.
- You may write the amount using locale decimal or use dot (.) as default.
- The only required dependency is angular!
- Min and Max validators like input[number].
If you use angular 1.2.x please, use 0.7.x version. If you use angular 1.3.x or above just use 0.8.x version instead.
You may install it via bower using
bower install ng-currency
You may see it in action and play a lot using plunker.
<iframe width="100%" src="http://embed.plnkr.co/u9mJqDH8UpwxDnOv8gZL/preview" frameborder="0" allowfullscreen></iframe>- Include the required libraries:
<script src="https://code.angularjs.org/1.2.16/angular.js"></script>
<script src="https://rawgit.com/aguirrel/ng-currency/master/src/ng-currency.js"></script>
- Inject the
ngCurrency
module into your app:
angular.module('myApp', ['ng-currency']);
- In your input tag
<input type="text" model="yourModel" ng-currency />
- It is also possible to add 'min' and 'max' validations
<input type="text" model="yourModel" ng-currency min="1" max="1337" />
- If you want to be able to dynamically enable/disable validations from a controller you can use the following
<input type="text" model="yourModel" ng-currency min="1" max="1337" ng-required="true" />
- It already shows the default currency symbol, but you can define a currency symbol, so that it will use this instead.
<input type="text" model="yourModel" ng-currency currency-symbol="¥" />
Please submit all pull requests the against master branch. If your unit test contains JavaScript patches or features, you should include relevant unit tests. Thanks!
Luis Aguirre
Guillermo Sandoval
Ronaldo Rogério Pereira
The MIT License
Copyright (c) 2012 - 2014 Olivier Louvignes
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.