Javascript 如何基于节点属性渲染角度材质平面树中的特定树节点?

Javascript 如何基于节点属性渲染角度材质平面树中的特定树节点?,javascript,angular,typescript,angular-material,angular7,Javascript,Angular,Typescript,Angular Material,Angular7,我想根据节点的nodeAuthorized:boolean属性显示特定的树节点。由于angular在单个元素上不允许超过2个结构指令,因此如何实现这一点 我尝试在的唯一子级上使用nodeAuthorized属性,但这会在两个或多个树节点之间呈现空白。如果有任何帮助,我们将不胜感激 这就是我尝试过的,但是,这在节点之间留下了明显的空白,这是我不想要的 <mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePa

我想根据节点的nodeAuthorized:boolean属性显示特定的树节点。由于angular在单个元素上不允许超过2个结构指令,因此如何实现这一点

我尝试在的唯一子级上使用nodeAuthorized属性,但这会在两个或多个树节点之间呈现空白。如果有任何帮助,我们将不胜感激

这就是我尝试过的,但是,这在节点之间留下了明显的空白,这是我不想要的

<mat-tree-node *matTreeNodeDef="let node; when: hasChild" matTreeNodePadding>
 <div *ngIf="node.treeNode.nodeAuthorized">   
  <button mat-icon-button matTreeNodeToggle>
   <mat-icon class="mat-icon-rtl-mirror">
    {{
       treeControl.isExpanded(node) ? "expand_more" : "chevron_right"
     }}
    </mat-icon>
   </button>

   {{node.treeNode.nodeName}}
 </div>
</mat-tree-node>
*matTreeNodeDef可以与之一起使用,然后可以与另一个HTML元素(比如说)和structural directive*ngIf一起使用,以呈现特定的节点

<ng-container *matTreeNodeDef="let node">
    <ng-container *ngIf="node.authorized"> /** node rendering condition goes here */
      <mat-tree-node matTreeNodePadding>
        <button mat-icon-button matTreeNodeToggle>
          <mat-icon class="mat-icon-rtl-mirror">
            {{treeControl.isExpanded(node) ? 'expand_more' : 'chevron_right'}}
          </mat-icon>
        </button>
        {{node.name}}
      </mat-tree-node>
    </ng-container>
  </ng-container>

你能给我举个例子吗?@Chandermani我用我的例子更新了我的答案。