Skip to content

Instantly share code, notes, and snippets.

@weeksdev
Created July 6, 2017 13:49
Show Gist options
  • Save weeksdev/1721ed0f142b3f53ceb9b400f8100d45 to your computer and use it in GitHub Desktop.
Save weeksdev/1721ed0f142b3f53ceb9b400f8100d45 to your computer and use it in GitHub Desktop.
angular currency format example
app.directive('currency', function () {
return {
require: 'ngModel',
link: function(elem, $scope, attrs, ngModel){
ngModel.$formatters.push(function(val){
return '$' + val
});
ngModel.$parsers.push(function(val){
return val.replace(/^\$/, '')
});
}
}
})
<input type="text" ng-model="price" currency>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment