是否可以在 Angular 中只打开一个树根节点?即,如果一个节点被展开,那么另一个打开的根节点应该崩溃。
有没有可能的方法来实现这一目标?
下面是我的树 .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>