Skip to content

Commit 153e65e

Browse files
authored
Merge pull request #2325 from adumesny/master
ng README fixes
2 parents ea25c65 + 5574429 commit 153e65e

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

demo/angular/README.md

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Angular wrapper
22

3-
The Angular [wrapper component](./gridstack.component.ts) <gridstack> is a better way to use Gridstack, but alternative raw [ngFor](./ngFor.ts) or [simple](./simple.ts) demos are also given.
3+
The Angular [wrapper component](src/gridstack.component.ts) <gridstack> is a better way to use Gridstack, but alternative raw [ngFor](src/ngFor.ts) or [simple](src/simple.ts) demos are also given.
4+
5+
**NOTE:** still having [issue](https://github.com/gridstack/gridstack.js/issues/2310) exporting the files to be included by Angular projects, so for now copy gridstack/dist/ng/src/* to your project and adjust the paths below.
46

57
# Dynamic grid items
68
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...
@@ -26,15 +28,21 @@ CSS
2628
}
2729
```
2830

29-
Code
31+
Your module Code
3032
```ts
31-
import { GridStack, GridStackOptions } from 'gridstack';
32-
import { gsCreateNgComponents } from 'gridstack/dist/ng/gridstack.component';
33+
import { GridstackModule } from 'gridstack/dist/ng/src/gridstack.module';
3334

34-
constructor() {
35-
// use the built in component creation code
36-
GridStack.addRemoveCB = gsCreateNgComponents;
37-
}
35+
@NgModule({
36+
imports: [GridstackModule, ...]
37+
...
38+
bootstrap: [AppComponent]
39+
})
40+
export class AppModule { }
41+
```
42+
43+
Component Code
44+
```ts
45+
import { GridStackOptions } from 'gridstack';
3846

3947
// sample grid options and items to load...
4048
public gridOptions: GridStackOptions = {
@@ -49,7 +57,7 @@ public gridOptions: GridStackOptions = {
4957
```
5058

5159
# More Complete example
52-
In this example will use your actual custom angular components inside each grid item (instead of dummy html content)
60+
In this example (build on previous one) will use your actual custom angular components inside each grid item (instead of dummy html content)
5361

5462
HTML
5563
```html
@@ -83,9 +91,6 @@ export class BComponent {
8391
constructor() {
8492
// register all our dynamic components created in the grid
8593
GridstackComponent.addComponentToSelectorType([AComponent, BComponent]);
86-
// set globally our method to create the right widget type
87-
GridStack.addRemoveCB = gsCreateNgComponents;
88-
GridStack.saveCB = gsSaveAdditionalNgInfo;
8994
}
9095

9196
// and now our content will look like instead of dummy html content
@@ -146,9 +151,9 @@ public identify(index: number, w: GridStackWidget) {
146151
```
147152

148153
## Demo
149-
You can see a fuller example at [app.component.ts](https://github.com/gridstack/gridstack.js/blob/master/demo/angular/src/app/app.component.ts)
154+
You can see a fuller example at [app.component.ts](src/app/app.component.ts)
150155

151-
to build the demo, go to demo/angular and run `yarn` + `yarn start` and Navigate to `http://localhost:4200/`
156+
to build the demo, go to demo/angular and run `yarn` + `yarn start` and navigate to `http://localhost:4200/`
152157

153158
Code now shipped starting with v8.0+ in dist/ng for people to use directly!
154159
## Caveats
@@ -159,7 +164,7 @@ Code now shipped starting with v8.0+ in dist/ng for people to use directly!
159164

160165
## *ngFor Caveats
161166
- 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,
162-
you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](./app.component.ts#L174) example.
167+
you must manually update the `GridstackItemComponent.option` directly - see [modifyNgFor()](src/app.component.ts#L174) example.
163168
- 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.
164169

165170

0 commit comments

Comments
 (0)