Setting Currency Value
$scope.model.currency = 10.20;
Implementing Directive
<div gl-currency="model.currency"></div>
Custom Directive Code
.directive('glCurrency', [function()
{
return {
scope:
{
glCurrency: '='
},
restrict: 'A',
templateUrl: 'currency.html',
link: function($scope, element, attrs)
{
$scope.$watch('glCurrency', function(currency)
{
if(currency)
{
var split = currency.toString().split('.');
if(Array.isArray(split))
{
$scope.number.dollars = split[0] ? split[0] : '0';
$scope.number.cents = split[1] ? split[1] : '00';
}
}
});
}
};
}]);
Display Template for Directive
<div class="currency">
<span class="currency__dollars">{{ number.dollars }}</span>
<span class="currency__cents">{{ number.cents }}</span>
</div>
Styling for the Currency Display
.currency {
position: relative;
}
.currency__dollars {
font-size: 24px;
padding-right: 10px;
}
.currency__cents {
font-size: 10px;
position: absolute;
top: 0;
right: 0;
}