3
3
* NOTE: see the simpler and better (tracks all changes) angular-ng-for-test
4
4
*/
5
5
6
- import { Component , AfterViewInit , Input , ViewChildren , QueryList } from " @angular/core" ;
6
+ import { Component , AfterViewInit , Input , ViewChildren , QueryList , ElementRef } from ' @angular/core' ;
7
7
import { Subject , zip } from "rxjs" ;
8
8
9
- import { GridStack , GridStackWidget } from 'gridstack' ;
9
+ import { GridItemHTMLElement , GridStack , GridStackWidget } from 'gridstack' ;
10
10
11
11
@Component ( {
12
12
selector : "angular-ng-for-cmd-test" ,
@@ -31,30 +31,24 @@ import { GridStack, GridStackWidget } from 'gridstack';
31
31
</div>
32
32
</div>
33
33
` ,
34
- styles : [
35
- `
36
- // !!!IMPORTANT!!! Import this through your styles.scss or angular.json! This is just for demo purposes
37
- :host {
38
- ::ng-deep {
39
- @import "demo";
40
- }
41
- }
42
- ` ,
43
- ] ,
34
+ // gridstack.min.css and other custom styles should be included in global styles.scss or here
44
35
} )
45
36
export class AngularNgForCmdTestComponent implements AfterViewInit {
46
- @ViewChildren ( "gridStackItem" ) gridstackItems ! : QueryList < any > ;
37
+ /** list of HTML items that we track to know when the DOM has been updated to make/remove GS widgets */
38
+ @ViewChildren ( "gridStackItem" ) gridstackItems ! : QueryList < ElementRef < GridItemHTMLElement > > ;
39
+
40
+ /** set the items to display. */
47
41
@Input ( ) public items : GridStackWidget [ ] = [
48
- { x : 0 , y : 0 , w : 1 , h : 1 } ,
49
- { x : 1 , y : 1 , w : 1 , h : 1 } ,
50
- { x : 2 , y : 2 , w : 1 , h : 1 } ,
42
+ { x : 0 , y : 0 } ,
43
+ { x : 1 , y : 1 } ,
44
+ { x : 2 , y : 2 } ,
51
45
] ;
52
46
53
47
private grid ! : GridStack ;
54
48
private widgetToMake : Subject < {
55
49
action : "add" | "remove" | "update" ;
56
50
id : number ;
57
- } > = new Subject ( ) ; // consider to use a statemanagement like ngrx component store to do this
51
+ } > = new Subject ( ) ; // consider to use a state management like ngrx component store to do this
58
52
59
53
constructor ( ) { }
60
54
@@ -79,9 +73,11 @@ export class AngularNgForCmdTestComponent implements AfterViewInit {
79
73
}
80
74
) ;
81
75
82
- // TODO: the problem with this code is that our items list does NOT reflect changes made by GS (user directly changing, or conflict)
83
- // and believe the other ngFor example (which does track changes) is also cleaner as it doesn't require special action commands
84
- // and track both changes to happen using zip().
76
+ // TODO: the problem with this code is that our items list does NOT reflect changes made by GS (user directly changing,
77
+ // or conflict during initial layout) and believe the other ngFor example (which does track changes) is also cleaner
78
+ // as it doesn't require user creating special action commands nor track 'both' changes using zip().
79
+ // TODO: identify() uses index which is not guaranteed to match between invocations (insert/delete in
80
+ // middle of list instead of end as demo does)
85
81
}
86
82
87
83
/**
@@ -103,6 +99,7 @@ export class AngularNgForCmdTestComponent implements AfterViewInit {
103
99
this . grid . update ( updateEl ! , { w : 2 } ) ;
104
100
}
105
101
102
+ // ngFor lookup indexing
106
103
identify ( index : number ) {
107
104
return index ;
108
105
}
0 commit comments