I've been working with Angular's currency filter and I've run into an issue. It doesn't seem to be filtering the data that is returned from a function. I have a feeling that I might be missing something, perhaps it has to do with how the filter gets digested?
Here are some snippets of my code:
HTML template file
<span>total: {{ vm.total.exgst | currency}}<span>
Controller.js for the HTML template
var calculateTotalExGST = function() { return _.sum(vm.items, function(item)
{ return item.cost; });
};
vm.total = { exgst: calculateTotalExGST() };
Currently, the HTML displays
total: 5
But ideally, it should display as $5.00. The value is being returned by the function, but the currency filter doesn't seem to work. Could it be related to when $digest happens?
Can anyone provide any insights on this issue?
Edit:
Just to provide more context about the code, vm.items
are values coming from $state
in ui-router.
I'm not sure how to replicate all of this in jsfiddler. So I've simply mocked $state. Unfortunately, I'm unable to reproduce my issue there.