Skip to content

Instantly share code, notes, and snippets.

@benjamincharity
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjamincharity/94b4a3f2377e4587ebb6 to your computer and use it in GitHub Desktop.
Save benjamincharity/94b4a3f2377e4587ebb6 to your computer and use it in GitHub Desktop.
angular.module('admin')
.directive('dollarsToCents', function(){
return {
require: 'ngModel',
link: function(scope, element, attrs, ngModel) {
if(ngModel) { // Don't do anything unless we have a model
ngModel.$parsers.push(function(value) {
return value*100;
});
ngModel.$formatters.push(function(value) {
return parseFloat(value/100).toFixed(2);
});
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment