Answer the question
In order to leave comments, you need to log in
How to hide name in navigation menu?
How to hide the name in the navigation menu for users with a specific role?
I do it like this:
import { Component, OnInit } from '@angular/core';
import {AuthService } from "../../services/auth/auth.service";
export interface RouteInfo {
path: string;
title: string;
icon: string;
class: string;
role: string[];
}
export const ROUTES: RouteInfo[] = [
{ path: 'notes', title: 'Заметки', icon: 'ti-comment', class: '', role:['Пользователь', 'Администратор'] },
{ path: 'contacts', title: 'Контакты', icon:'ti-info', class: '', role:['Пользователь', 'Администратор'] },
{ path: 'users', title: 'Пользователи', icon:'ti-user', class: '', role:['Пользователь', 'Администратор'] },
{ path: 'admins', title: 'Администрирование', icon:'ti-server', class: '', role:['Администратор'] }
];
@Component({
selector: 'app-sidebar',
templateUrl: './sidebar.component.html',
styleUrls: ['./sidebar.component.css']
})
export class SidebarComponent implements OnInit {
public menuItems: any[];
constructor(
public authService:AuthService
) {
}
ngOnInit() {
this.menuItems = ROUTES.filter(menuItem => menuItem.role.includes(this.authService.currentUserData.role));
}
}
ERROR TypeError: Cannot read property 'role' of undefined
at eval (sidebar.component.ts:39)
at Array.filter ()
at SidebarComponent.ngOnInit (sidebar.component.ts:39)
at checkAndUpdateDirectiveInline (core.es5.js: 10843)
at checkAndUpdateNodeInline (core.es5.js:12341)
at checkAndUpdateNode (core.es5.js:12284)
at debugCheckAndUpdateNode (core.es5.js:13141)
at debugCheckDirectivesFn (core.es5.js:13082)
at Object.eval [as updateDirectives] (LayoutComponent.html:3)
at Object.debugUpdateDirectives [as updateDirectives] (core.es5.js:13067)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question