@@ -4,15 +4,18 @@ import { of as observableOf } from 'rxjs';
44import { FlatTreeControl } from '@angular/cdk/tree' ;
55import { files } from './example-data' ;
66
7- /** File node data with nested structure . */
7+ /** File node data with possible child nodes . */
88export interface FileNode {
99 name : string ;
1010 type : string ;
1111 children ?: FileNode [ ] ;
1212}
1313
14- /** Flat node with expandable and level information */
15- export interface TreeNode {
14+ /**
15+ * Flattened tree node that has been created from a FileNode through the flattener. Flattened
16+ * nodes include level index and whether they can be expanded or not.
17+ */
18+ export interface FlatTreeNode {
1619 name : string ;
1720 type : string ;
1821 level : number ;
@@ -37,22 +40,22 @@ export interface TreeNode {
3740export class < %= classify ( name ) % > Component {
3841
3942 /** The TreeControl controls the expand/collapse state of tree nodes. */
40- treeControl : FlatTreeControl < TreeNode > ;
43+ treeControl : FlatTreeControl < FlatTreeNode > ;
4144
4245 /** The TreeFlattener is used to generate the flat list of items from hierarchical data. */
43- treeFlattener : MatTreeFlattener < FileNode , TreeNode > ;
46+ treeFlattener : MatTreeFlattener < FileNode , FlatTreeNode > ;
4447
4548 /** The MatTreeFlatDataSource connects the control and flattener to provide data. */
46- dataSource : MatTreeFlatDataSource < FileNode , TreeNode > ;
49+ dataSource : MatTreeFlatDataSource < FileNode , FlatTreeNode > ;
4750
4851 constructor ( ) {
4952 this . treeFlattener = new MatTreeFlattener (
5053 this . transformer ,
5154 this . getLevel ,
5255 this . isExpandable ,
5356 this . getChildren ) ;
54-
55- this . treeControl = new FlatTreeControl < TreeNode > ( this . getLevel , this . isExpandable ) ;
57+
58+ this . treeControl = new FlatTreeControl ( this . getLevel , this . isExpandable ) ;
5659 this . dataSource = new MatTreeFlatDataSource ( this . treeControl , this . treeFlattener ) ;
5760 this . dataSource . data = files ;
5861 }
@@ -67,23 +70,23 @@ export class <%= classify(name) %>Component {
6770 } ;
6871 }
6972
70- /** Get the level of the node */
71- getLevel ( node : TreeNode ) {
73+ /** Get the level of the node */
74+ getLevel ( node : FlatTreeNode ) {
7275 return node . level ;
7376 }
7477
7578 /** Get whether the node is expanded or not. */
76- isExpandable ( node : TreeNode ) {
79+ isExpandable ( node : FlatTreeNode ) {
7780 return node . expandable ;
7881 } ;
7982
83+ /** Get whether the node has children or not. */
84+ hasChild ( index : number , node : FlatTreeNode ) {
85+ return node . expandable ;
86+ }
87+
8088 /** Get the children for the node. */
8189 getChildren ( node : FileNode ) {
8290 return observableOf ( node . children ) ;
8391 }
84-
85- /** Get whether the node has children or not. */
86- hasChild ( index : number , node : TreeNode ) {
87- return node . expandable ;
88- }
8992}
0 commit comments