首页 > 解决方案 > 如何根据条件禁用 Mat-tree 组件?

问题描述

我正在使用Angular Material 6。我无法禁用我的 mat-tree 组件:

<mat-tree>
    <!-- // -->
</mat-tree>

标签: angulartypescriptangular-materialangular6

解决方案


<any-component *ngIf='your_condition' ... > </any-component>

会工作。例如,

 <any-component *ngIf='isShown == true' ... > </any-component>

编辑:我需要在 UI 上显示它。我需要把整棵树变灰

你可以使用@disabled属性

<mat-tree>
  <mat-tree-node [disabled]='isDisabled'> parent node </mat-tree-node>
  <mat-tree-node [disabled]='isDisabled'> -- child node1 </mat-tree-node>
  <mat-tree-node [disabled]='isDisabled'> -- child node2 </mat-tree-node>
</mat-tree>

推荐阅读