Q:

Optimize AngularJS ngHide attribute

 <span ng-hide="(getStatusIcon(inactive.currentStatus.code).statusDesc) =='Expired' ||
                (getStatusIcon(inactive.currentStatus.code).statusDesc) =='Rejected' ||
                (getStatusIcon(inactive.currentStatus.code).statusDesc) =='Refused'">
 PO# [[inactive.poNumber]] 
 </span>

I would like to optimize the code
If the getStatusIcon(inactive.currentStatus.code).statusDesc is (expired , refused rejected)
we are hiding the span tag. Right now we are calling the function 3 times.
is there a way to check getStatusIcon(inactive.currentStatus.code).statusDesc in (expired , refused rejected).
Calling the function only once.

A:

You can use ng-init to only call the function once:
  <span ng-init="statusDesc = getStatusIcon(inactive.currentStatus.code).statusDesc" 
        ng-hide="(statusDesc) =='Expired' || 
                 (statusDesc) =='Rejected' || 
                 (statusDesc) =='Refused'">
  PO# [[inactive.poNumber]] 
  </span>

And then you should probably place your comparsions in the controller.
<span ng-init="statusDesc = getStatusIcon(inactive.currentStatus.code).statusDesc" 
      ng-hide="isInvalidStatusDesc(statusDesc)">
PO# {{inactive.poNumber}}
</span>

function mainCtrl($scope) {
    $scope.isInvalidStatusDesc = function(statusDesc) {
      switch (statusDesc) {
        case 'Expired':
        case 'Rejected':
        case 'Refused':
          return true;
        default:
          return false;
      }
    }; 
}

