/ng-currency

ng-currency

Primary LanguageJavaScript

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].

Bower

You may install it via bower using

bower install ng-currency

Example

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>

Quick start

  • Include the required libraries:
<script src="https://code.angularjs.org/1.2.16/angular.js"></script>
<script src="http://aguirrel.github.io/ng-currency/dist/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" />

Contributing

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!

Authors

Luis Aguirre

Contributors

Guillermo Sandoval

Copyright and license

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.