简体   繁体   English

Angular Material tree - 造型的可能性

[英]Angular Material tree - styling possibilites

I am choosing angular material tree component over the FancyTree js component because of typescript support.由于打字稿支持,我选择了角度材料树组件而不是FancyTree js 组件

I find that the material tree component does not have many options for styling except for colors (theming).我发现材质树组件除了颜色(主题)之外没有太多样式选项。

How to make the material tree component look like the following fancy tree style ?如何使材质树组件看起来像下面的花式树样式

FancyTree also has interesting event binding functionality, does the material tree provide this as well? FancyTree 也有有趣的事件绑定功能,材质树也有这个功能吗?

You can add events and style it the way you like.您可以添加事件并按照您喜欢的方式设置样式。 According to your link for "Fancy tree style" the only thing you need it to style text the way you like (font-family, font-size, font-weight etc) and add one more material icon for controlling open state for folder as in my example code below:根据您的“Fancy tree style”链接,您唯一需要的是按照您喜欢的方式设置文本样式(字体系列、字体大小、字体粗细等),并添加一个材料图标来控制文件夹的打开状态在我下面的示例代码中:

<cdk-nested-tree-node
*cdkTreeNodeDef="let node; when: hasChild"
class="tree-node"
>
<button
  mat-icon-button
  [attr.aria-label]="'toggle ' + node.name"
  cdkTreeNodeToggle
>
  <mat-icon class="mat-icon-rtl-mirror">
    {{ treeControl.isExpanded(node) ? "expand_more" : "chevron_right" }}
  </mat-icon>
  //here is an additional icon and conditional to follow up with open close state which is actually what you wanted if I am not mistaken 
  <mat-icon class="mat-icon-rtl-mirror">
    {{ treeControl.isExpanded(node) ? "folder" : "folder_open" }}
  </mat-icon>
  //icon ends here 
</button>

{{ node.name }}
<div [class.tree-invisible]="!treeControl.isExpanded(node)">
  <ng-container cdkTreeNodeOutlet></ng-container>
</div>

so you get similar to this look and feel as the link you provided ("Fancy tree style"):所以你会得到类似于你提供的链接的外观和感觉(“Fancy tree style”):

在此处输入图像描述

I hope this helps!我希望这有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM