@@ -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 ;
@@ -37,22 +40,22 @@ export interface TreeNode {
37
40
export class < %= classify ( name ) % > Component {
38
41
39
42
/** The TreeControl controls the expand/collapse state of tree nodes. */
40
- treeControl : FlatTreeControl < TreeNode > ;
43
+ treeControl : FlatTreeControl < FlatTreeNode > ;
41
44
42
45
/** The TreeFlattener is used to generate the flat list of items from hierarchical data. */
43
- treeFlattener : MatTreeFlattener < FileNode , TreeNode > ;
46
+ treeFlattener : MatTreeFlattener < FileNode , FlatTreeNode > ;
44
47
45
48
/** The MatTreeFlatDataSource connects the control and flattener to provide data. */
46
- dataSource : MatTreeFlatDataSource < FileNode , TreeNode > ;
49
+ dataSource : MatTreeFlatDataSource < FileNode , FlatTreeNode > ;
47
50
48
51
constructor ( ) {
49
52
this . treeFlattener = new MatTreeFlattener (
50
53
this . transformer ,
51
54
this . getLevel ,
52
55
this . isExpandable ,
53
56
this . getChildren ) ;
54
-
55
- this . treeControl = new FlatTreeControl < TreeNode > ( this . getLevel , this . isExpandable ) ;
57
+
58
+ this . treeControl = new FlatTreeControl ( this . getLevel , this . isExpandable ) ;
56
59
this . dataSource = new MatTreeFlatDataSource ( this . treeControl , this . treeFlattener ) ;
57
60
this . dataSource . data = files ;
58
61
}
@@ -67,23 +70,23 @@ export class <%= classify(name) %>Component {
67
70
} ;
68
71
}
69
72
70
- /** Get the level of the node */
71
- getLevel ( node : TreeNode ) {
73
+ /** Get the level of the node */
74
+ getLevel ( node : FlatTreeNode ) {
72
75
return node . level ;
73
76
}
74
77
75
78
/** Get whether the node is expanded or not. */
76
- isExpandable ( node : TreeNode ) {
79
+ isExpandable ( node : FlatTreeNode ) {
77
80
return node . expandable ;
78
81
} ;
79
82
83
+ /** Get whether the node has children or not. */
84
+ hasChild ( index : number , node : FlatTreeNode ) {
85
+ return node . expandable ;
86
+ }
87
+
80
88
/** Get the children for the node. */
81
89
getChildren ( node : FileNode ) {
82
90
return observableOf ( node . children ) ;
83
91
}
84
-
85
- /** Get whether the node has children or not. */
86
- hasChild ( index : number , node : TreeNode ) {
87
- return node . expandable ;
88
- }
89
92
}
0 commit comments