Question

I have a site that will be displaying lots of number entry fields. The user will be entering the numbers, or using large plus & minus buttons to increment them.

These numbers will be things like age, annual income, percentages, or consumer prices.

I want to build a single, standard way of dealing with these numbers.

I explored the filters like {{priceOfCoffee | currency}}, which will work for those simple items, but when I get to the others, I have extra requirements.

For example, I want the annual income to have a $ prepended, group the 000s but have no decimal. I'll also want to restrict input to only numbers, etc.

I know I can do these with custom filters, or directives, but I'm just not sure whether it makes sense to create several custom filters, or a directive to which I can pass parameters.

Thoughts?

Thanks, Scott

Was it helpful?

Solution

If you only care about formatting a single piece of text use a filter. If you want to reuse an entire block of content use a directive. It's difficult to be more specific with only a generic description of the application.

I had an application where I got medication information from the server which I needed to format, but I also wanted to use it in multiple places in the app. So I made a directive so I could reuse the entire block of content, but within that directive information about the dosage was formatted with filters.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top