In Angular JS application I need to show user the result of the javascript function (heavyFunction in my example), which depends on user input, so I am using {{}} to show the result.
I need to show it only in certain conditions, so I am also invoking this function in ng-show and ng-class directives.
<span ng-show="heavyFunction() > 0" ng:class="{true:'red', false:'blue'}[heavyFunction() > 5]"> {{heavyFunction()}} </span>
The problem is that I am invoking function three time, instead of one time. What is the best practice in Angular JS to invoke this function only once?
Plunker: https://plnkr.co/edit/9r5AlA3RbtZLseOCOzPX?p=preview