Skip to content

Instantly share code, notes, and snippets.

@markcoleman
Created February 26, 2013 21:00
Show Gist options
  • Save markcoleman/5042147 to your computer and use it in GitHub Desktop.
Save markcoleman/5042147 to your computer and use it in GitHub Desktop.
Simple AngularJs directive that adds a positive and negative class to the element, using the built in currency filter
angular.module('homeBanking.directives', [])
.directive("hbCurrency", ($filter: ng.IFilterService) => {
return {
restrict: "EAC",
require: "?$filter",
link: function ($scope: ng.IScope, elm, attrs) {
var currencyFilter = $filter('currency'),
rawAmount = $scope.$eval(attrs.hbCurrency),
className = rawAmount >= 0 ? "positive" : "negative";
elm.text(currencyFilter(rawAmount)).addClass(className);
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment