I'm using angular 5 material and I have a JSON object containing menu and submenu's data. how should I do it?
I can show the items with type= link or sub but I don't know how to show the children. I want to show the child items when clicking on the parent.
I used mat-nav-list and mat-list-item to show them but I don't know how to show the children.
here is the object:
import { Injectable } from '@angular/core';
export interface ChildrenItems {
state: string;
name: string;
type?: string;
}
export interface Menu {
state: string;
name: string;
type: string;
icon: string;
children?: ChildrenItems[];
}
const MENUITEMS = [
{
state: 'dashboard',
name: 'Dashboard',
type: 'link',
icon: 'dashboard'
},
{
state: 'setting',
name: 'Settings',
type: 'sub',
icon: 'settings',
children: [
{
state: 'station_management',
name: 'Station Management',
type: 'parent',
grand_children: [
{ state: 'station', name: 'Station' },
{ state: 'shifts_work', name: 'Shifts Work' },
{ state: 'fuel_price', name: 'Fule Price' },
{ state: 'tank_management', name: 'Tank Management' }
]
}
]
}
];
@Injectable()
export class MenuItems {
getMenuitem(): Menu[] {
return MENUITEMS;
}
}
