Angular one time binding ng-if multiple conditions

1.7k views Asked by At

In my templates i've got a lot of conditions related to my user rights and products rights, for example:

<div ng-if="user.rights == 'admin'  || user.rights == 'owner'  || products.rights.technical"></div>

Thoses rights can't be changed without going to a new page... so I was thinking that I could use one-binding :: for better performance.

I tried:

<div ng-if="::(user.rights == 'admin'  || user.rights == 'owner'  || products.rights.technical)"></div>

and also:

<div ng-if="::user.rights == 'admin'  || ::user.rights == 'owner'  || ::products.rights.technical"></div>

but the condition doesn't seems to work, any idea ?

1

There are 1 answers

1
Sachet Gupta On

Probably, compute user.rights == 'admin' || user.rights == 'owner' || products.rights.technical at page load and assign it to another scope variable (say $scope.isOwnerOrAdmin). And then, use one way binding to bind this variable to ng-if. like: ng-if="::$scope.isOwnerOrAdmin".