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

Dynamic Nested Menu from JSON upto 4 levels #264

Open
Ameya1991 opened this issue Nov 21, 2018 · 0 comments
Open

Dynamic Nested Menu from JSON upto 4 levels #264

Ameya1991 opened this issue Nov 21, 2018 · 0 comments

Comments

@Ameya1991
Copy link

Ameya1991 commented Nov 21, 2018

am having issues working with the nested-menu and nested classes while trying to generate dynamic menu using ngFor & ngIf.

Similar sidenav with Material example is available here

Model Class

export interface NavItems {
  displayName: string;
  disabled?: boolean;
  iconName: string;
  route?: string;
  children?: NavItems[];
}

<!-- Component.html -->

<span *ngFor="let item of navItems">
  <span *ngIf="item.children && item.children.length > 0">
     <div style="background-color:darkcyan">{{item.displayName}}</div>
        <app-menu-item #menu [items]="item.children"></app-menu-item>
  </span>
  <span *ngIf="!item.children || item.children.length === 0">
       <div style="background-color:crimson">{{item.displayName}}</div>
  </span>
</span>

<!-- app-menu-item  (for iteration) -->

<span *ngFor="let item of items">
  <span *ngIf="item.children && item.children.length > 0">
    <div style="background-color: darkorchid">{{item.displayName}}</div>
    <app-menu-item #menu [items]="item.children"></app-menu-item>
  </span>
  <span *ngIf="!item.children || item.children.length === 0">
    <div style="background-color:chartreuse">{{item.displayName}}</div>
  </span>
</span>


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

1 participant