42 lines
844 B
TypeScript
42 lines
844 B
TypeScript
import { Component, OnInit, Input } from '@angular/core';
|
|
import { Router } from '@angular/router'
|
|
|
|
@Component({
|
|
selector: 'app-sidebar-menu',
|
|
templateUrl: './sidebar-menu.component.html',
|
|
styleUrls: ['./sidebar-menu.component.scss']
|
|
})
|
|
export class SidebarMenuComponent implements OnInit {
|
|
//输入数据
|
|
@Input() data: Array<any>;
|
|
|
|
constructor(
|
|
private router: Router
|
|
) { }
|
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
/**
|
|
* 判断是否有子节点
|
|
* @param item
|
|
*/
|
|
isLeaf(item: any) {
|
|
return !item.children || !item.children.length;
|
|
}
|
|
|
|
/**
|
|
* 菜单点击事件
|
|
* @param item
|
|
*/
|
|
itemClicked(item: any) {
|
|
if (!this.isLeaf(item)) {
|
|
item.isExpend = !item.isExpend;
|
|
} else {
|
|
this.router.navigate([item.path])
|
|
}
|
|
}
|
|
|
|
}
|