Skip to content

Commit e11db35

Browse files
authored
Merge pull request #2773 from adumesny/master
fix angular doc
2 parents f9014b2 + 98f4e6b commit e11db35

File tree

1 file changed

+34
-22
lines changed

1 file changed

+34
-22
lines changed

angular/README.md

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,27 @@
11
# Angular wrapper
22

3-
The Angular [wrapper component](projects/lib/src/lib/gridstack.component.ts) <gridstack> is a better way to use Gridstack, but alternative raw [ngFor](projects/demo/src/app/ngFor.ts) or [simple](projects/demo/src/app/simple.ts) demos are also given.
3+
The Angular [wrapper component](projects/lib/src/lib/gridstack.component.ts) <gridstack> is a <b>better way to use Gridstack</b>, but alternative raw [ngFor](projects/demo/src/app/ngFor.ts) or [simple](projects/demo/src/app/simple.ts) demos are also given.
44

55
# Dynamic grid items
6+
67
this is the recommended way if you are going to have multiple grids (alow drag&drop between) or drag from toolbar to create items, or drag to remove items, etc...
78

89
I.E. don't use Angular templating to create grid items as that is harder to sync when gridstack will also add/remove items.
910

10-
HTML
11+
HTML
12+
1113
```html
12-
<gridstack [options]="gridOptions">
13-
</gridstack>
14+
<gridstack [options]="gridOptions"></gridstack>
1415
```
1516

1617
CSS
18+
1719
```css
1820
@import "gridstack/dist/gridstack.min.css";
21+
@import "gridstack/dist/gridstack-extra.min.css"; // if you use 2-11 column
1922

2023
.grid-stack {
21-
background: #FAFAD2;
24+
background: #fafad2;
2225
}
2326
.grid-stack-item-content {
2427
text-align: center;
@@ -27,6 +30,7 @@ CSS
2730
```
2831

2932
in your module Code
33+
3034
```ts
3135
import { GridstackModule } from 'gridstack/dist/angular';
3236

@@ -39,6 +43,7 @@ export class AppModule { }
3943
```
4044

4145
Component Code
46+
4247
```ts
4348
import { GridStackOptions } from 'gridstack';
4449

@@ -54,16 +59,19 @@ public gridOptions: GridStackOptions = {
5459
```
5560

5661
# More Complete example
62+
5763
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).
5864

59-
HTML
65+
HTML
66+
6067
```html
6168
<gridstack [options]="gridOptions" (changeCB)="onChange($event)">
6269
<div empty-content>message when grid is empty</div>
6370
</gridstack>
6471
```
6572

6673
Code
74+
6775
```ts
6876
import { Component } from '@angular/core';
6977
import { GridStack, GridStackOptions } from 'gridstack';
@@ -113,18 +121,19 @@ public onChange(data: nodesCB) {
113121
```
114122

115123
# ngFor with wrapper
124+
116125
For simple case where you control the children creation (gridstack doesn't do create or re-parenting)
117126

118-
HTML
127+
HTML
128+
119129
```html
120130
<gridstack [options]="gridOptions" (changeCB)="onChange($event)">
121-
<gridstack-item *ngFor="let n of items; trackBy: identify" [options]="n">
122-
Item {{n.id}}
123-
</gridstack-item>
131+
<gridstack-item *ngFor="let n of items; trackBy: identify" [options]="n"> Item {{n.id}} </gridstack-item>
124132
</gridstack>
125133
```
126134

127135
Code
136+
128137
```javascript
129138
import { GridStackOptions, GridStackWidget } from 'gridstack';
130139
import { nodesCB } from 'gridstack/dist/angular';
@@ -149,22 +158,25 @@ public identify(index: number, w: GridStackWidget) {
149158
```
150159

151160
## Demo
161+
152162
You can see a fuller example at [app.component.ts](projects/demo/src/app/app.component.ts)
153163

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

156166
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`)
157-
## Caveats
158167

159-
- This wrapper needs:
160-
- gridstack v8 to run as it needs the latest changes (use older version that matches GS versions)
161-
- Angular 13+ for dynamic createComponent() API
168+
## Caveats
169+
170+
- This wrapper needs:
171+
- gridstack v8 to run as it needs the latest changes (use older version that matches GS versions)
172+
- Angular 13+ for dynamic createComponent() API
173+
174+
## ngFor Caveats
175+
176+
- This wrapper handles well ngFor loops, but if you're using a trackBy function (as I would recommend) and no element id change after an update,
177+
you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](./projects/demo/src/app/app.component.ts#L202) example.
178+
- The original client list of items is not updated to match **content** changes made by gridstack (TBD later), but adding new item or removing (as shown in demo) will update those new items. Client could use change/added/removed events to sync that list if they wish to do so.
162179

163-
## *ngFor Caveats
164-
- This wrapper handles well ngFor loops, but if you're using a trackBy function (as I would recommend) and no element id change after an update,
165-
you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](src/app/app.component.ts#L174) example.
166-
- The original client list of items is not updated to match **content** changes made by gridstack (TBD later), but adding new item or removing (as shown in demo) will update those new items. Client could use change/added/removed events to sync that list if they wish to do so.
180+
Would appreciate getting help doing the same for React and Vue (2 other popular frameworks)
167181

168-
Would appreciate getting help doing the same for React and Vue (2 other popular frameworks)
169-
170-
-Alain
182+
-Alain

0 commit comments

Comments
 (0)