Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<mat-tree #tree [dataSource]="dataSource" [childrenAccessor]="childrenAccessor">
<mat-tree #tree [dataSource]="dataSource()" [childrenAccessor]="childrenAccessor">
<mat-tree-node *matTreeNodeDef="let node" matTreeNodePadding>
<button matIconButton disabled></button>
{{node.name}}
Expand All @@ -15,4 +15,4 @@
<mat-progress-bar mode="indeterminate" class="example-tree-progress-bar"></mat-progress-bar>
}
</mat-tree-node>
</mat-tree>
</mat-tree>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {Component, Service, inject, signal} from '@angular/core';
import {Component, Service, WritableSignal, inject, signal} from '@angular/core';
import {MatProgressBarModule} from '@angular/material/progress-bar';
import {MatIconModule} from '@angular/material/icon';
import {MatButtonModule} from '@angular/material/button';
Expand All @@ -9,7 +9,7 @@ interface DynamicNode {
name: string;
level: number;
expandable: boolean;
isLoading: ReturnType<typeof signal<boolean>>;
isLoading: WritableSignal<boolean>;
children?: DynamicNode[];
}

Expand Down Expand Up @@ -63,12 +63,9 @@ export class DynamicDatabase {
})
export class TreeDynamicExample {
private _database = inject(DynamicDatabase);

dataSource = this._database.initialData();

childrenAccessor = (node: DynamicNode) => node.children ?? [];

hasChild = (_: number, node: DynamicNode) => node.expandable;
readonly dataSource = signal(this._database.initialData());
readonly childrenAccessor = (node: DynamicNode) => node.children ?? [];
readonly hasChild = (_: number, node: DynamicNode) => node.expandable;

/**
* Load children on node expansion.
Expand All @@ -93,6 +90,7 @@ export class TreeDynamicExample {
this._database.createNode(name, node.level + 1, this._database.isExpandable(name)),
);
node.isLoading.set(false);
this.dataSource.set([...this.dataSource()]);
}, 1000);
}
}
Loading