Skip to content

Commit 5b945e5

Browse files
authored
Merge pull request #2348 from adumesny/master
ng Readme update
2 parents ecba3a4 + 1069522 commit 5b945e5

File tree

1 file changed

+21
-21
lines changed

1 file changed

+21
-21
lines changed

angular/README.md

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,16 @@ import { GridStackOptions } from 'gridstack';
4545
// sample grid options + items to load...
4646
public gridOptions: GridStackOptions = {
4747
margin: 5,
48-
float: true,
4948
children: [ // or call load()/addWidget() with same data
5049
{x:0, y:0, minW:2, content:'Item 1'},
51-
{x:1, y:1, content:'Item 2'},
52-
{x:2, y:2, content:'Item 3'},
50+
{x:1, y:0, content:'Item 2'},
51+
{x:0, y:1, content:'Item 3'},
5352
]
5453
}
5554
```
5655

5756
# More Complete example
58-
In this example (build on previous one) will use your actual custom angular components inside each grid item (instead of dummy html content)
57+
In this example (build on previous one) will use your actual custom angular components inside each grid item (instead of dummy html content) and have per component saved settings as well (using BaseWidget).
5958

6059
HTML
6160
```html
@@ -68,21 +67,26 @@ Code
6867
```ts
6968
import { Component } from '@angular/core';
7069
import { GridStack, GridStackOptions } from 'gridstack';
71-
import { GridstackComponent, gsCreateNgComponents, NgGridStackWidget, nodesCB } from 'gridstack/dist/angular';
70+
import { GridstackComponent, gsCreateNgComponents, NgGridStackWidget, nodesCB, BaseWidget } from 'gridstack/dist/angular';
7271

7372
// some custom components
7473
@Component({
7574
selector: 'app-a',
76-
template: 'Comp A', // your real ng content goes in each component instead...
75+
template: 'Comp A {{text}}',
7776
})
78-
export class AComponent {
77+
export class AComponent extends BaseWidget implements OnDestroy {
78+
@Input() text: string = 'foo'; // test custom input data
79+
public override serialize(): NgCompInputs | undefined { return this.text ? {text: this.text} : undefined; }
80+
ngOnDestroy() {
81+
console.log('Comp A destroyed'); // test to make sure cleanup happens
82+
}
7983
}
8084

8185
@Component({
8286
selector: 'app-b',
8387
template: 'Comp B',
8488
})
85-
export class BComponent {
89+
export class BComponent extends BaseWidget {
8690
}
8791

8892
// .... in your module for example
@@ -94,12 +98,11 @@ constructor() {
9498
// now our content will use Components instead of dummy html content
9599
public gridOptions: NgGridStackOptions = {
96100
margin: 5,
97-
float: true,
98101
minRow: 1, // make space for empty message
99102
children: [ // or call load()/addWidget() with same data
100-
{x:0, y:0, minW:2, type:'app-a'},
101-
{x:1, y:1, type:'app-b'},
102-
{x:2, y:2, content:'plain html content'},
103+
{x:0, y:0, minW:2, selector:'app-a'},
104+
{x:1, y:0, selector:'app-b'},
105+
{x:0, y:1, content:'plain html content'},
103106
]
104107
}
105108

@@ -127,14 +130,11 @@ import { GridStackOptions, GridStackWidget } from 'gridstack';
127130
import { nodesCB } from 'gridstack/dist/angular';
128131

129132
/** sample grid options and items to load... */
130-
public gridOptions: GridStackOptions = {
131-
margin: 5,
132-
float: true,
133-
}
133+
public gridOptions: GridStackOptions = { margin: 5 }
134134
public items: GridStackWidget[] = [
135135
{x:0, y:0, minW:2, id:'1'}, // must have unique id used for trackBy
136-
{x:1, y:1, id:'2'},
137-
{x:2, y:2, id:'3'},
136+
{x:1, y:0, id:'2'},
137+
{x:0, y:1, id:'3'},
138138
];
139139

140140
// called whenever items change size/position/etc..
@@ -149,11 +149,11 @@ public identify(index: number, w: GridStackWidget) {
149149
```
150150

151151
## Demo
152-
You can see a fuller example at [app.component.ts](src/app/app.component.ts)
152+
You can see a fuller example at [app.component.ts](projects/demo/src/app/app.component.ts)
153153

154-
to build the demo, go to angular/projects/demo and run `yarn` + `yarn start` and navigate to `http://localhost:4200/`
154+
to build the demo, go to [angular/projects/demo](projects/demo/) and run `yarn` + `yarn start` and navigate to `http://localhost:4200/`
155155

156-
Code now shipped starting with v8.1.2+ in `dist/angular` for people to use directly! (source code under `dist/angular/src`)
156+
Code ship starting with v8.1.2+ in `dist/angular` for people to use directly and is an angular module! (source code under `dist/angular/src`)
157157
## Caveats
158158

159159
- This wrapper needs:

0 commit comments

Comments
 (0)