import { Component, OnInit } from '@angular/core'; import { MenuModel } from 'app/my-layout/menu.model'; import { menuList } from 'app/my-layout/my-layout.component'; @Component({ selector: 'app-index', templateUrl: './index.component.html', styleUrls: ['./index.component.css'] }) export class IndexComponent implements OnInit { public gridStyle = { width : '25%', textAlign: 'center' }; public menu: MenuModel[] = []; public constructor() { } public ngOnInit() { let res: MenuModel[] = []; menuList.forEach( x => { if (x.children.length) { res = res.concat(x.children); } else { res.push(x); } }); this.menu = res; } }