import { Component, OnInit, ViewChild } from '@angular/core'; import { TreeModel, Ng2TreeSettings, NodeEvent } from 'ng2-tree'; @Component({ selector: 'lib-saga-tree', templateUrl: './saga-tree.component.html', styleUrls: ['./saga-tree.component.css'] }) export class SagaTreeComponent implements OnInit { public tree: TreeModel = { value: 'Programming languages by programming paradigm', id:"1", children: [ { value: 'Object-oriented programming', id:'11', children: [ { id:'110',value: 'Java' }, { id:'111',value: 'C++' }, { id:'112',value: 'C#' } ] }, { value: 'Prototype-based programming', id:'12', children: [ { id:'120',value: 'JavaScript' }, { id:'121',value: 'CoffeeScript' }, { id:'122',value: 'Lua' } ] } ] }; public CurrentIndex = 1; CurrentSelected: any; @ViewChild('ToolsTree') public ToolsTree: any; public settings: Ng2TreeSettings = { rootIsVisible: true }; onNodeSelected(e: NodeEvent): void { if (e.node.isLeaf()) { this.CurrentSelected = e.node; console.log(e.node.parent.id + " " + e.node.id); var path = e.node.parent.id; var id = e.node.id; // this.toolService.sendModelInfoMessage(path,id); } else { this.CurrentSelected = undefined; const thisControl = this.ToolsTree.getControllerByNodeId(e.node.id); e.node.isNodeCollapsed() ? thisControl.expand() : thisControl.collapse(); //? this.modelService.clearMessage? 移除右侧的模型信息? } } constructor() { } ngOnInit() { // this.initTree(); this.CurrentSelected = null; } }