diff --git a/demo/angular/src/app/app.component.html b/demo/angular/src/app/app.component.html
index fbf1d6e29..d76695e4a 100644
--- a/demo/angular/src/app/app.component.html
+++ b/demo/angular/src/app/app.component.html
@@ -35,7 +35,6 @@
- {{n.content}}
@@ -46,6 +45,9 @@
+
+
+
@@ -57,8 +59,8 @@
-
+
diff --git a/demo/angular/src/app/app.module.ts b/demo/angular/src/app/app.module.ts
index 92d47cb0a..3447611a5 100644
--- a/demo/angular/src/app/app.module.ts
+++ b/demo/angular/src/app/app.module.ts
@@ -3,11 +3,12 @@ import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { GridstackItemComponent } from './gridstack-item.component';
-import { GridstackComponent } from './gridstack.component';
+import { GridstackComponent, gsCreateNgComponents, gsSaveAdditionNgInfo } from './gridstack.component';
import { AngularNgForTestComponent } from './ngFor';
import { AngularNgForCmdTestComponent } from './ngFor_cmd';
import { AngularSimpleComponent } from './simple';
import { AComponent, BComponent, CComponent } from './dummy.component';
+import { GridStack } from 'gridstack';
@NgModule({
declarations: [
@@ -34,10 +35,9 @@ import { AComponent, BComponent, CComponent } from './dummy.component';
export class AppModule {
constructor() {
// register all our dynamic components created in the grid
- GridstackComponent.selectorToType = {
- 'app-a': AComponent,
- 'app-b': BComponent,
- 'app-c': CComponent,
- };
+ GridstackComponent.addComponentToSelectorType([AComponent, BComponent, CComponent]);
+ // set globally our method to create the right widget type
+ GridStack.addRemoveCB = gsCreateNgComponents; // DONE in case switcher onShow() as well
+ GridStack.saveCB = gsSaveAdditionNgInfo;
}
}
diff --git a/demo/angular/src/app/gridstack-item.component.ts b/demo/angular/src/app/gridstack-item.component.ts
index e7f58ca0e..329514380 100644
--- a/demo/angular/src/app/gridstack-item.component.ts
+++ b/demo/angular/src/app/gridstack-item.component.ts
@@ -3,7 +3,7 @@
* Copyright (c) 2022 Alain Dumesny - see GridStack root license
*/
-import { ChangeDetectionStrategy, Component, ElementRef, Input, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core';
+import { Component, ElementRef, Input, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core';
import { GridItemHTMLElement, GridStackNode } from 'gridstack';
/** store element to Ng Class pointer back */
@@ -28,7 +28,7 @@ export interface GridItemCompHTMLElement extends GridItemHTMLElement {
styles: [`
:host { display: block; }
`],
- changeDetection: ChangeDetectionStrategy.OnPush,
+ // changeDetection: ChangeDetectionStrategy.OnPush, // IFF you want to optimize and control when ChangeDetection needs to happen...
})
export class GridstackItemComponent implements OnDestroy {
@@ -42,8 +42,7 @@ export class GridstackItemComponent implements OnDestroy {
this.el.gridstackNode.grid.update(this.el, val);
} else {
// store our custom element in options so we can update it and not re-create a generic div!
- val.el = this.el;
- this._options = val;
+ this._options = {...val, el: this.el};
}
}
/** return the latest grid options (from GS once built, otherwise initial values) */
diff --git a/demo/angular/src/app/gridstack.component.ts b/demo/angular/src/app/gridstack.component.ts
index 26bb2e3bc..3869c4700 100644
--- a/demo/angular/src/app/gridstack.component.ts
+++ b/demo/angular/src/app/gridstack.component.ts
@@ -3,8 +3,8 @@
* Copyright (c) 2022 Alain Dumesny - see GridStack root license
*/
-import { AfterContentInit, ChangeDetectionStrategy, Component, ContentChildren, ElementRef, EventEmitter, Input,
- NgZone, OnDestroy, OnInit, Output, QueryList, Type, ViewChild, ViewContainerRef, createComponent, EnvironmentInjector } from '@angular/core';
+import { AfterContentInit, Component, ContentChildren, ElementRef, EventEmitter, Input,
+ OnDestroy, OnInit, Output, QueryList, Type, ViewChild, ViewContainerRef, reflectComponentType } from '@angular/core';
import { Subject } from 'rxjs';
import { takeUntil } from 'rxjs/operators';
import { GridHTMLElement, GridItemHTMLElement, GridStack, GridStackNode, GridStackOptions, GridStackWidget } from 'gridstack';
@@ -17,7 +17,6 @@ export type elementCB = {event: Event, el: GridItemHTMLElement};
export type nodesCB = {event: Event, nodes: GridStackNode[]};
export type droppedCB = {event: Event, previousNode: GridStackNode, newNode: GridStackNode};
-
/** extends to store Ng Component selector, instead/inAddition to content */
export interface NgGridStackWidget extends GridStackWidget {
type?: string; // component type to create as content
@@ -31,6 +30,7 @@ export interface GridCompHTMLElement extends GridHTMLElement {
_gridComp?: GridstackComponent;
}
+/** selector string to runtime Type mapping */
export type SelectorToType = {[key: string]: Type