我需要以角度获取树的根节点名称,但 node.name 将“节点”作为值。
下面是我的 .html 代码部分:
<mat-tree [dataSource]="dataSource" [treeControl]="treeControl"
class="example-tree">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodeToggle
(click)="selectedItem = node.name;" >
{{node.name}}
</mat-tree-node>
<mat-nested-tree-node *matTreeNodeDef="let node; when: hasChild"
>
<div class="mat-tree-node">
<button mat-icon-button matTreeNodeToggle
[attr.aria-label]="'Toggle ' + node.name"
(click)="selectedItem = node.name; NodeCollapse(node.name)">
<mat-icon class="mat-icon-rtl-mirror">
{{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
</mat-icon>
</button>
{{node.name}}
</div>
<div [class.example-tree-invisible]="!treeControl.isExpanded(node)"
role="group">
<ng-container matTreeNodeOutlet></ng-container>
</div>
</mat-nested-tree-node>
</mat-tree>
下面是我的 Component.ts 代码,其中包含我在 Node Button-Icon Click 上调用的 Method(NodeCollapse) 定义:
NodeCollapse(n_name:string):void{
let nodename:string=n_name;
if(Node.name)
{
}
}
下面是我的浏览器源调试器: Browser Source debugger