@@ -4,15 +4,18 @@ import { of as observableOf } from 'rxjs';
4
4
import { FlatTreeControl } from '@angular/cdk/tree' ;
5
5
import { files } from './example-data' ;
6
6
7
- /** File node data with nested structure . */
7
+ /** File node data with possible child nodes . */
8
8
export interface FileNode {
9
9
name : string ;
10
10
type : string ;
11
11
children ?: FileNode [ ] ;
12
12
}
13
13
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 {
16
19
name : string ;
17
20
type : string ;
18
21
level : number ;
@@ -61,22 +64,22 @@ export interface TreeNode {
61
64
export class < %= classify ( name ) % > Component {
62
65
63
66
/** The TreeControl controls the expand/collapse state of tree nodes. */
64
- treeControl : FlatTreeControl < TreeNode > ;
67
+ treeControl : FlatTreeControl < FlatTreeNode > ;
65
68
66
69
/** The TreeFlattener is used to generate the flat list of items from hierarchical data. */
67
- treeFlattener : MatTreeFlattener < FileNode , TreeNode > ;
70
+ treeFlattener : MatTreeFlattener < FileNode , FlatTreeNode > ;
68
71
69
72
/** The MatTreeFlatDataSource connects the control and flattener to provide data. */
70
- dataSource : MatTreeFlatDataSource < FileNode , TreeNode > ;
73
+ dataSource : MatTreeFlatDataSource < FileNode , FlatTreeNode > ;
71
74
72
75
constructor ( ) {
73
76
this . treeFlattener = new MatTreeFlattener (
74
77
this . transformer ,
75
78
this . getLevel ,
76
79
this . isExpandable ,
77
80
this . getChildren ) ;
78
-
79
- this . treeControl = new FlatTreeControl < TreeNode > ( this . getLevel , this . isExpandable ) ;
81
+
82
+ this . treeControl = new FlatTreeControl ( this . getLevel , this . isExpandable ) ;
80
83
this . dataSource = new MatTreeFlatDataSource ( this . treeControl , this . treeFlattener ) ;
81
84
this . dataSource . data = files ;
82
85
}
@@ -91,23 +94,23 @@ export class <%= classify(name) %>Component {
91
94
} ;
92
95
}
93
96
94
- /** Get the level of the node */
95
- getLevel ( node : TreeNode ) {
97
+ /** Get the level of the node */
98
+ getLevel ( node : FlatTreeNode ) {
96
99
return node . level ;
97
100
}
98
101
99
102
/** Get whether the node is expanded or not. */
100
- isExpandable ( node : TreeNode ) {
103
+ isExpandable ( node : FlatTreeNode ) {
101
104
return node . expandable ;
102
105
} ;
103
106
107
+ /** Get whether the node has children or not. */
108
+ hasChild ( index : number , node : FlatTreeNode ) {
109
+ return node . expandable ;
110
+ }
111
+
104
112
/** Get the children for the node. */
105
113
getChildren ( node : FileNode ) {
106
114
return observableOf ( node . children ) ;
107
115
}
108
-
109
- /** Get whether the node has children or not. */
110
- hasChild ( index : number , node : TreeNode ) {
111
- return node . expandable ;
112
- }
113
116
}
0 commit comments