I have created a new role ROLE_SUPERUSER in my jhipster application. I want a specific navbar menu to be visible to only admin and my new user. I tried using has-any-authorithy as given in authority.directive.js but its not working.
I am using it in HTML like
has-any-authorithy="['ROLE_ADMIN','ROLE_SUPERUSER']"
Am I missing anything?
Code says:
authorities = attrs.hasAnyAuthority.replace(/\s+/g, '').split(',');
So it seems that the directive expects one string and not an array.
Try this:
has-any-authority="ROLE_ADMIN, ROLE_SUPERUSER"
There is a better way to do this. You can create a service only for this directive and return a "joined" array like this :
code in your service :
this.feature_1 = {
access: [ROLES.ROLE_ADMIN, ROLES.ROLE_SUPERUSER].join()
};
ROLES is a constant and an array of app roles defined in app.constants.js.
And in your template :
has-any-roles="{{accessService.feature_1.access}}"
By doing this, if you want to change the access rights, you have only to modify the accessService
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With