I have the following directive that helps me to split the decimals from a number and present it with different styles in my view. Thing is, it does not update when the value changes.
I use this directive many many times to present in the view currencies related to money.
This is the directive:
app.directive('money', function(){
return {
restrict: 'E'
, scope: {
money: '@'
}
, controller: controller
, controllerAs: 'dvm'
, bindToController: true
, template: '<h2><sup>$</sup>{{ dvm.dollar }}<sub>.{{ dvm.cents }}</sub></h2>'
};
function controller(){
var parts = parseFloat(this.money).toFixed(2).split(/\./);
this.dollar = parts[0];
this.cents = parts[1];
}
});
I update the values several times depending on the user options, so these values are re-calculated every time the user picks options.
Currently, none of those values are updated when they are re-calculated. What is the better way to solve this?