1- import { Component , Service , inject , signal } from '@angular/core' ;
1+ import { Component , Service , WritableSignal , inject , signal } from '@angular/core' ;
22import { MatProgressBarModule } from '@angular/material/progress-bar' ;
33import { MatIconModule } from '@angular/material/icon' ;
44import { 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} )
6464export 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