Dynamic nested Material menu from json object in Angular 5

后端 未结 2 1106
轻奢々
轻奢々 2021-01-31 09:09

How to create dynamic nested menu from json object?

I started using Angular Material Design today for the first time and I\'m trying to create nested menus using materia

2条回答
  •  借酒劲吻你
    2021-01-31 09:46

    Here is a StackBlitz example of an arbitrarily deep nesting based on JSON (authored by @Splaktar)

    The key to arbitrary nesting is the self-referencing menu-item.component:

    import {Component, Input, OnInit, ViewChild} from '@angular/core';
    import {Router} from '@angular/router';
    import {NavItem} from '../nav-item';
    
    @Component({
      selector: 'app-menu-item',
      templateUrl: './menu-item.component.html',
      styleUrls: ['./menu-item.component.scss']
    })
    export class MenuItemComponent implements OnInit {
      @Input() items: NavItem[];
      @ViewChild('childMenu') public childMenu;
    
      constructor(public router: Router) {
      }
    
      ngOnInit() {
      }
    }
    
    
      
        
        
          
          
        
        
        
          
        
      
    
    

提交回复
热议问题