|
29 | 29 | } |
30 | 30 | ``` |
31 | 31 |
|
32 | | -in your module Code |
33 | | - |
34 | | -```ts |
35 | | -import { GridstackModule } from 'gridstack/dist/angular'; |
36 | | - |
37 | | -@NgModule({ |
38 | | - imports: [GridstackModule, ...] |
39 | | - ... |
40 | | - bootstrap: [AppComponent] |
41 | | -}) |
42 | | -export class AppModule { } |
43 | | -``` |
44 | | - |
45 | 32 | Component Code |
46 | 33 |
|
47 | 34 | ```ts |
48 | 35 | import { GridStackOptions } from 'gridstack'; |
| 36 | +import { GridstackComponent, GridstackItemComponent } from 'gridstack/dist/angular'; |
49 | 37 |
|
50 | | -// sample grid options + items to load... |
51 | | -public gridOptions: GridStackOptions = { |
52 | | - margin: 5, |
53 | | - children: [ // or call load()/addWidget() with same data |
54 | | - {x:0, y:0, minW:2, content:'Item 1'}, |
55 | | - {x:1, y:0, content:'Item 2'}, |
56 | | - {x:0, y:1, content:'Item 3'}, |
| 38 | +@Component({ |
| 39 | + imports: [ |
| 40 | + GridstackComponent, |
| 41 | + GridstackItemComponent |
57 | 42 | ] |
| 43 | + ... |
| 44 | + }) |
| 45 | +export class MyComponent { |
| 46 | + // sample grid options + items to load... |
| 47 | + public gridOptions: GridStackOptions = { |
| 48 | + margin: 5, |
| 49 | + children: [ // or call load()/addWidget() with same data |
| 50 | + {x:0, y:0, minW:2, content:'Item 1'}, |
| 51 | + {x:1, y:0, content:'Item 2'}, |
| 52 | + {x:0, y:1, content:'Item 3'}, |
| 53 | + ] |
| 54 | + } |
| 55 | + |
58 | 56 | } |
59 | 57 | ``` |
60 | 58 |
|
@@ -97,11 +95,16 @@ export class AComponent extends BaseWidget implements OnDestroy { |
97 | 95 | export class BComponent extends BaseWidget { |
98 | 96 | } |
99 | 97 |
|
100 | | -// .... in your module for example |
101 | | -constructor() { |
102 | | - // register all our dynamic components types created by the grid |
103 | | - GridstackComponent.addComponentToSelectorType([AComponent, BComponent]); |
104 | | -} |
| 98 | +// in your app.config for example |
| 99 | +export const appConfig: ApplicationConfig = { |
| 100 | + providers: [ |
| 101 | + ... |
| 102 | + provideEnvironmentInitializer(() => { |
| 103 | + // register all our dynamic components created in the grid |
| 104 | + GridstackComponent.addComponentToSelectorType([AComponent, BComponent]); |
| 105 | + }) |
| 106 | + ] |
| 107 | +}; |
105 | 108 |
|
106 | 109 | // now our content will use Components instead of dummy html content |
107 | 110 | public gridOptions: NgGridStackOptions = { |
@@ -175,7 +178,7 @@ Code started shipping with v8.1.2+ in `dist/angular` for people to use directly |
175 | 178 |
|
176 | 179 | - This wrapper needs: |
177 | 180 | - gridstack v8 to run as it needs the latest changes (use older version that matches GS versions) |
178 | | - - Angular 14+ for dynamic `createComponent()` API |
| 181 | + - Angular 14+ for dynamic `createComponent()` API and Standalone Components |
179 | 182 |
|
180 | 183 | NOTE: if you are on Angular 13 or below: copy the wrapper code over (or patch it - see main page example) and change `createComponent()` calls to use old API instead: |
181 | 184 | ```ts |
|
0 commit comments