33 * NOTE: see the simpler and better (tracks all changes) angular-ng-for-test
44 */
55
6- import { Component , AfterViewInit , Input , ViewChildren , QueryList } from " @angular/core" ;
6+ import { Component , AfterViewInit , Input , ViewChildren , QueryList , ElementRef } from ' @angular/core' ;
77import { Subject , zip } from "rxjs" ;
88
9- import { GridStack , GridStackWidget } from 'gridstack' ;
9+ import { GridItemHTMLElement , GridStack , GridStackWidget } from 'gridstack' ;
1010
1111@Component ( {
1212 selector : "angular-ng-for-cmd-test" ,
@@ -31,30 +31,24 @@ import { GridStack, GridStackWidget } from 'gridstack';
3131 </div>
3232 </div>
3333 ` ,
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
4435} )
4536export 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. */
4741 @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 } ,
5145 ] ;
5246
5347 private grid ! : GridStack ;
5448 private widgetToMake : Subject < {
5549 action : "add" | "remove" | "update" ;
5650 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
5852
5953 constructor ( ) { }
6054
@@ -79,9 +73,11 @@ export class AngularNgForCmdTestComponent implements AfterViewInit {
7973 }
8074 ) ;
8175
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)
8581 }
8682
8783 /**
@@ -103,6 +99,7 @@ export class AngularNgForCmdTestComponent implements AfterViewInit {
10399 this . grid . update ( updateEl ! , { w : 2 } ) ;
104100 }
105101
102+ // ngFor lookup indexing
106103 identify ( index : number ) {
107104 return index ;
108105 }
0 commit comments