Hi,
I have a use case that is quite common, and I don’t know how to tackle it. I have an array of data that show growths, and data look like this:
[
{percent: -85, trend: 'negative'},
{percent: 65, trend: 'positive'}
]
Therefore, I created a component to display each growth (with the value, and an icon for the trend. I need a component because this is reused in a lot of different pages. I pass this array to my component as “growths” variable. My template of my component looks like this:
{{#each growth in growths}}
{{growth.percent}}
{{/each}}
The issue is that I need to display a different icon depending on wether the trend is positive or negative:
{{#each growth in growths}}
{{growth.percent}}
{{#if growth.trend == 'positive'}}
<i class="icon-positive"></i>
{{else}}
<i class="icon-negative"></i>
{{/if}}
{{/each}}
But as this is not possible in Handlebars, I would need to use a computed property. However as I’m in the context of the compoennt, I don’t see a clean way to do that. The simplest way I’ve found is to create a new component (growth-details), that will wrap the positive or negative trend inside a computed property. But this leads to a lot of very small component.
{{#each growth in growths}}
{{growth-details growth=growth}}
{{/each}}
Is there a better way to tackle this problem? Inside a controller, this is easy to solve thanks to itemController, but I can’t see a clean way with components only.
Thanks!