Angular directive to format an input as a currency as the user types. Like autoNumeric for Angular.
http://bcherny.github.io/format-as-currency/demo
Install via bower or NPM:
- Bower:
bower install --save format-as-currency
- NPM:
npm install --save format-as-currency
<div ng-controller="myController">
<input
format-as-currency
ng-model="value"
type="text"
>
</div>
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/format-as-currency/format-as-currency.js"></script>
<script>
angular
.module('myModule', [
'bcherny/formatAsCurrency'
])
.controller('myController', function ($scope) {
$scope.value = '' // currency input value
})
</script>
<input
format-as-currency
currency-filter="'yuan'"
ng-model="value"
type="text"
>
<script>
angular
...
.filter('yuan', function ($filter) {
return function (value) {
return $filter('currency')(value, '¥')
}
})
</script>
<input
format-as-currency
currency-filter="'myFilter'"
ng-model="value"
type="text"
>
<script>
angular
...
.filter('myFilter', function () {
return function (value) {
return '¥' + value
}
})
</script>
var formatAsCurrency = require('format-as-currency')
angular.module('myModule', [formatAsCurrency])
import * as formatAsCurrency from 'format-as-currency'
angular.module('myModule', [formatAsCurrency])
var formatAsCurrency = require('format-as-currency/src/format-as-currency')
angular.module('myModule', [formatAsCurrency])
npm test
Contributions are welcome! Please be sure to:
- File an issue for the problem that your PR addresses
- Test your fix thoroughly
- Follow the existing code style
- Add unit tests to cover your feature, or to prevent future regressions