Skip to content

Commit e023fee

Browse files
committed
Fix(cdk-tree): initialize cdk-tree component datasource in the constructor
1 parent 3ce0d4e commit e023fee

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/app/angular/cdk-tree/cdk-tree.component.ts

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ArrayDataSource } from '@angular/cdk/collections';
1+
import { ArrayDataSource, DataSource } from '@angular/cdk/collections';
22
import { FlatTreeControl } from '@angular/cdk/tree';
33
import { Component } from '@angular/core';
44
import { ExampleFlatNode } from './cdk-tree.model';
@@ -11,14 +11,17 @@ import { CdkTreeService } from './cdk-tree.service';
1111
})
1212
export class CdkTreeComponent {
1313
static selector = 'appCdkTree';
14-
private readonly treeData: ExampleFlatNode[] = this.cdkTreeService.getTreeData();
15-
treeControl = new FlatTreeControl<ExampleFlatNode>(
14+
private readonly treeData: ExampleFlatNode[];
15+
readonly treeControl = new FlatTreeControl<ExampleFlatNode>(
1616
node => node.level,
1717
node => node.expandable
1818
);
19-
dataSource = new ArrayDataSource(this.treeData);
19+
readonly dataSource: DataSource<ExampleFlatNode>;
2020

21-
constructor(private cdkTreeService: CdkTreeService) {}
21+
constructor(private cdkTreeService: CdkTreeService) {
22+
this.treeData = this.cdkTreeService.getTreeData();
23+
this.dataSource = new ArrayDataSource(this.treeData);
24+
}
2225

2326
hasChild = (_: number, node: ExampleFlatNode) => node.expandable;
2427

0 commit comments

Comments
 (0)