I have an array of prices (0, 0.99, 1.99... etc) that I want to display in .
I want to use Angular\
There's a better way:
app.filter('price', function() {
return function(num) {
return num === 0 ? 'free' : num + '$';
};
});
Then use it like this:
This way, the filter is useful for single values, rather than operating only on arrays. If you have objects and corresponding formatting filters, this is quite useful.
Filters can also be used directly in code, if you need them:
var formattedPrice = $filter('price')(num);