Created
February 26, 2013 21:00
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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