Allow users to input dollars while keeping your model dealing with cents. Credit: http://stackoverflow.com/a/18743619/722367 & http://stackoverflow.com/questions/6095795/convert-a-javascript-string-variable-to-decimal-money
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);
});
}
}
};
});