I am looping through list of items using ng-repeat. There are some values which i want to display as simple numbers like "435" or "43", some i want to display as double like with 2 decimal places "545,32.43" or "343.32", some values are percentage which i want to display like "75%", and some are currency which i want to display as "$65,434".
I know angularjs provides filters for all kinds of operations (number, currency, percentage) etc.
But how can i chose one of the filter dynamically based on condition?
javascript
config:[
{key:"Issue County",value:50,valColor:'#4caeed', type:'integer',dec_places:0},
{key:"Issue Average", value:10.5356 ,valColor:'#4caeed', type:'double', dec_places:2},
{key:"Issues Percentage", value:57, valColor:'#e54343', type:'percentage', dec_places:2},
{key:"Total Amount", value:65000, valColor:'#4ca977', type:'currency', dec_places:0}
]
html
<ui class="subCardDiv" ng-repeat="conf in item.config">
<li style="display: inline;">
<span class="cardDivKey" style="padding-top: 2px;">{{conf.key}} </span>
<span class="cardDivVal" ng-style="{color:conf.valColor}" style="padding-top: 2px;">{{conf.value | number:conf.dec_places}} </span>
<span ng-if="conf.text" class="cardDivText" style="padding-top: 2px;">{{conf.text}} </span>
</li>
</ui>
confobject to it. Inject the$filterservice and call the appropriate filter when you need to (see this answer for how to do that).