Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular reuse function value from controller in view for an item

I have an application which uses angular and in the view I call a controller function to hide/show a div but also needs the value from the return of the function. Code is as folowing

<div class="item-icon-right" ng_show="getClass(item.jsonpath) !== ''">
        <i class="icon ion-record getClass(item.jsonpath)"></i>
      </div>

You see that getClass is called twice for an item. Is it possible to store the value and reuse it?

like image 778
luca.p.alexandru Avatar asked Aug 08 '26 04:08

luca.p.alexandru


1 Answers

You can simply store the returned value in new variable and use it for i class:

<div class="item-icon-right" ng_show="(itemClass = getClass(item.jsonpath)) !== ''">
    <i class="icon ion-record {{ itemClass }}"></i>
</div>
like image 90
dfsq Avatar answered Aug 09 '26 16:08

dfsq



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!