Home > Software design >  Reading dynamic value for *jhiHasAnyAuthority
Reading dynamic value for *jhiHasAnyAuthority

Time:07-13

I am new to Angular and jhipster stack, we are building an angular - spring-boot project with jhipster stack. For rendering the menu items in the Nav Bar we are using '*jhiHasAnyAuthority' in the navbar.component.html like below:

<li *jhiHasAnyAuthority="'ROLE_ADMIN' ngbDropdown routerLinkActive="active">

Is there any way we can read the value for jhiHasAnyAuthority dynamically?

CodePudding user response:

You could get a reference to the instance of the directive via ViewChild

@ViewChild(HasAnyAuthorityDirective)
set authorityDirective(val: HasAnyAuthorityDirective) {
    this._authorityDirective = val;
};

You'll be able to check the values it contains then

CodePudding user response:

Not sure what you mean by "dynamically" but you can inject AccountService into the constructor of your component and use its functions and in particular hasAnyAuthority(). This is what the directive uses. Look at its definition in src/main/webapp/app/core/auth/account.service.ts of your project.

There are many examples on how it is used in your generated project.

  • Related