Skip to content

Commit 0262a4f

Browse files
authored
docs(material/tree): dynamic example not updating (#33365)
Fixes that the dynamic tree example didn't render any data once it loads. Fixes #33336.
1 parent 03685a9 commit 0262a4f

2 files changed

Lines changed: 8 additions & 10 deletions

File tree

src/components-examples/material/tree/tree-dynamic/tree-dynamic-example.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<mat-tree #tree [dataSource]="dataSource" [childrenAccessor]="childrenAccessor">
1+
<mat-tree #tree [dataSource]="dataSource()" [childrenAccessor]="childrenAccessor">
22
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding>
33
<button matIconButton disabled></button>
44
{{node.name}}
@@ -15,4 +15,4 @@
1515
<mat-progress-bar mode="indeterminate" class="example-tree-progress-bar"></mat-progress-bar>
1616
}
1717
</mat-tree-node>
18-
</mat-tree>
18+
</mat-tree>

src/components-examples/material/tree/tree-dynamic/tree-dynamic-example.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {Component, Service, inject, signal} from '@angular/core';
1+
import {Component, Service, WritableSignal, inject, signal} from '@angular/core';
22
import {MatProgressBarModule} from '@angular/material/progress-bar';
33
import {MatIconModule} from '@angular/material/icon';
44
import {MatButtonModule} from '@angular/material/button';
@@ -9,7 +9,7 @@ interface DynamicNode {
99
name: string;
1010
level: number;
1111
expandable: boolean;
12-
isLoading: ReturnType<typeof signal<boolean>>;
12+
isLoading: WritableSignal<boolean>;
1313
children?: DynamicNode[];
1414
}
1515

@@ -63,12 +63,9 @@ export class DynamicDatabase {
6363
})
6464
export class TreeDynamicExample {
6565
private _database = inject(DynamicDatabase);
66-
67-
dataSource = this._database.initialData();
68-
69-
childrenAccessor = (node: DynamicNode) => node.children ?? [];
70-
71-
hasChild = (_: number, node: DynamicNode) => node.expandable;
66+
readonly dataSource = signal(this._database.initialData());
67+
readonly childrenAccessor = (node: DynamicNode) => node.children ?? [];
68+
readonly hasChild = (_: number, node: DynamicNode) => node.expandable;
7269

7370
/**
7471
* Load children on node expansion.
@@ -93,6 +90,7 @@ export class TreeDynamicExample {
9390
this._database.createNode(name, node.level + 1, this._database.isExpandable(name)),
9491
);
9592
node.isLoading.set(false);
93+
this.dataSource.set([...this.dataSource()]);
9694
}, 1000);
9795
}
9896
}

0 commit comments

Comments
 (0)