Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide a item in navItems #60

Closed
pnthree opened this issue May 3, 2019 · 3 comments
Closed

Hide a item in navItems #60

pnthree opened this issue May 3, 2019 · 3 comments

Comments

@pnthree
Copy link

pnthree commented May 3, 2019

How Can i hide a item in array navItems?

@xidedix
Copy link
Member

xidedix commented May 4, 2019

hi @pnthree

_nav.ts returns a configuration object to populate sidebar-nav

  • static way: in _nav.ts add hidden attribute to item:
{
  name: 'Colors',
  url: '/theme/colors',
  icon: 'icon-drop',
  attributes: { hidden: true }
 },
  • dynamic way: write an angular service to set up nav config object dynamically, and subscribe the result in default-layout.component

see also:

@pnthree
Copy link
Author

pnthree commented May 6, 2019 via email

@xidedix xidedix closed this as completed May 6, 2019
@xidedix xidedix changed the title Hide a item in navIItems Hide a item in navItems May 6, 2019
@SekouSallah
Copy link

I created a service called authentication in the services folder located at the root of the project. In this service I created a hasRole method which allows you to see if the user has a role and return true. As you can see: public hasRole(roles: string[]): boolean {
const storedUserRoles = localStorage.getItem("userRoles");

if (storedUserRoles) {
  const userRoles = JSON.parse(storedUserRoles);
  return roles.some(role => userRoles.includes(role));
}

return false;

}. Now I want to display this sidebar element only if the user has the "ADMIN" or "PATIENT" role. {
name: 'Add patient',
url: '/base/add-patient',
iconComponent: { name: 'eyelash-puzzle' },
attributes: { hidden: (authService: AuthenticationService) => authService.hasRole(['ADMIN']) }
}, at the hidden level it has no effect because it is displayed whether the user has the ADMIN role or not. Help me please

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants