I have an 3 user rights - Admin, User, and Editor. The way this is setup is:
If you are an Admin
the return is roles: ["Admin", "User", "Editor"]
If you are an User
the return is roles: ["User"]
If you are an Editor
the return is roles: ["User", "Editor"]
Now what I have now is ng-show="object.roles.length < 2" = User
and etc. for the other two.
I am sure there is a better/smarter way to do this or maybe it is easier to do it this way. I am just not sure how to go about it differently. Thanks for the suggestions.
Or, to be cleaner, delegate to a scope function:
and
That is not a good idea. You are managing your app's UI by counting an array length. What if this changes? I would suggest to verify always if the role needed is owned. For example
ng-show="hasRole('User')"
This worked for me:
It will not show
if == 0
, otherwise it will.