1
1
import { Component , OnInit , ViewChild , ElementRef } from '@angular/core' ;
2
2
import { GridStack , GridStackOptions , GridStackWidget } from 'gridstack' ;
3
- import { GridstackComponent , NgGridStackWidget , elementCB , nodesCB } from './gridstack.component' ;
3
+ import { GridstackComponent , NgGridStackWidget , elementCB , gsCreateNgComponents , nodesCB } from './gridstack.component' ;
4
+ import { AngularSimpleComponent } from './simple' ;
5
+ import { AngularNgForTestComponent } from './ngFor' ;
6
+ import { AngularNgForCmdTestComponent } from './ngFor_cmd' ;
4
7
5
8
// unique ids sets for each item for correct ngFor updating
6
9
let ids = 1 ;
@@ -11,12 +14,15 @@ let ids = 1;
11
14
} )
12
15
export class AppComponent implements OnInit {
13
16
17
+ @ViewChild ( AngularSimpleComponent ) case0Comp ?: AngularSimpleComponent ;
18
+ @ViewChild ( AngularNgForTestComponent ) case1Comp ?: AngularNgForTestComponent ;
19
+ @ViewChild ( AngularNgForCmdTestComponent ) case2Comp ?: AngularNgForCmdTestComponent ;
14
20
@ViewChild ( GridstackComponent ) gridComp ?: GridstackComponent ;
15
21
@ViewChild ( 'origTextArea' , { static : true } ) origTextEl ?: ElementRef < HTMLTextAreaElement > ;
16
22
@ViewChild ( 'textArea' , { static : true } ) textEl ?: ElementRef < HTMLTextAreaElement > ;
17
23
18
24
// which sample to show
19
- public show = 6 ; // nested
25
+ public show = 6 ;
20
26
21
27
/** sample grid options and items to load... */
22
28
public items : GridStackWidget [ ] = [
@@ -74,15 +80,37 @@ export class AppComponent implements OnInit {
74
80
// setTimeout(() => {
75
81
// if (!this.gridComp) return;
76
82
// this.saveGrid();
77
- // this.clearGrid();
78
- // // this.loadGrid();
83
+ // // this.clearGrid();
84
+ // this.delete();
85
+ // this.delete();
86
+ // this.loadGrid();
87
+ // this.delete();
88
+ // this.delete();
79
89
// }, 500)
80
90
}
81
91
82
92
public onShow ( val : number ) {
83
93
this . show = val ;
84
- const data = val === 6 ? this . nestedGridOptions : this . gridOptionsFull ;
85
- if ( this . origTextEl ) this . origTextEl . nativeElement . value = JSON . stringify ( data , null , ' ' ) ;
94
+
95
+ // set globally our method to create the right widget type
96
+ if ( val < 3 ) GridStack . addRemoveCB = undefined ;
97
+ else GridStack . addRemoveCB = gsCreateNgComponents ;
98
+
99
+ // let the switch take affect then load the starting values (since we sometimes save())
100
+ setTimeout ( ( ) => {
101
+ let data ;
102
+ switch ( val ) {
103
+ case 0 : data = this . case0Comp ?. items ; break ;
104
+ case 1 : data = this . case1Comp ?. items ; break ;
105
+ case 2 : data = this . case2Comp ?. items ; break ;
106
+ case 3 : data = this . gridComp ?. grid ?. save ( true , true ) ; break ;
107
+ case 4 : data = this . items ; break ;
108
+ case 5 : data = this . gridOptionsFull ; break ;
109
+ case 6 : data = this . nestedGridOptions ; break ;
110
+ }
111
+ if ( this . origTextEl ) this . origTextEl . nativeElement . value = JSON . stringify ( data , null , ' ' ) ;
112
+ } ) ;
113
+ if ( this . textEl ) this . textEl . nativeElement . value = '' ;
86
114
87
115
// if (val === 6 && !this.gridComp) {
88
116
// const cont: HTMLElement | null = document.querySelector('.grid-container');
0 commit comments