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

How to make a dynamic sidebar menu? #161

Closed
hleder-web opened this issue Oct 1, 2019 · 4 comments
Closed

How to make a dynamic sidebar menu? #161

hleder-web opened this issue Oct 1, 2019 · 4 comments

Comments

@hleder-web
Copy link

hleder-web commented Oct 1, 2019

im trying to use use a json on the place of nav.ts to make the nav itens dynamic depending on the user, but i dont know how can i do it.

interface NavAttributes {
[propName: string]: any;
}
interface NavWrapper {
attributes: NavAttributes;
element: string;
}
interface NavBadge {
text: string;
variant: string;
}
interface NavLabel {
class?: string;
variant: string;
}

export interface NavData {
name?: string;
url?: string;
icon?: string;
badge?: NavBadge;
title?: boolean;
children?: NavData[];
variant?: string;
attributes?: NavAttributes;
divider?: boolean;
class?: string;
label?: NavLabel;
wrapper?: NavWrapper;
}

export const navItems: NavData[] = [
---------json here--------------

];

@xidedix
Copy link
Member

xidedix commented Oct 2, 2019

Hi @hleder-web
Please take a look here: #143

@Hagith
Copy link

Hagith commented Oct 8, 2019

The easiest option is to create an Observable which emits current sidebar items depending on your custom logic. Example:

sidebar-service.ts

@Injectable()
class AppSidebarService {
  items$: Observable<INavData[]>;

  constructor(private user: UserService) {
    this.items$ = this.user.state$.pipe(
      map(user => this.getSidebarItems(user)),
    );
  }

  private getSidebarItems(user: User): INavData[] {
    // logic depending on user context
    return [ /* sidebar items */];
  }
}

sidebar.html

<app-sidebar-nav [navItems]="sidebar.items$ | async"></app-sidebar-nav>

@RNKushwaha
Copy link

How sidebar.items$ is available in html? In my case it says Property 'sidebar' does not exist on type 'DefaultLayoutComponent'.

@github-actions
Copy link

github-actions bot commented May 8, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions

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

No branches or pull requests

4 participants