55
66import { AfterContentInit , Component , ContentChildren , ElementRef , EventEmitter , Input ,
77 OnDestroy , OnInit , Output , QueryList , Type , ViewChild , ViewContainerRef , reflectComponentType , ComponentRef } from '@angular/core' ;
8- import { Subject } from 'rxjs' ;
9- import { takeUntil } from 'rxjs/operators' ;
8+ import { Subscription } from 'rxjs' ;
109import { GridHTMLElement , GridItemHTMLElement , GridStack , GridStackNode , GridStackOptions , GridStackWidget } from 'gridstack' ;
1110
1211import { GridItemCompHTMLElement , GridstackItemComponent } from './gridstack-item.component' ;
@@ -119,8 +118,8 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
119118
120119 private _options ?: GridStackOptions ;
121120 private _grid ?: GridStack ;
121+ private _sub : Subscription | undefined ;
122122 private loaded ?: boolean ;
123- private ngUnsubscribe : Subject < void > = new Subject ( ) ;
124123
125124 constructor (
126125 // private readonly zone: NgZone,
@@ -142,21 +141,20 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
142141 /** wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first) */
143142 public ngAfterContentInit ( ) : void {
144143 // track whenever the children list changes and update the layout...
145- this . gridstackItems ?. changes
146- . pipe ( takeUntil ( this . ngUnsubscribe ) )
147- . subscribe ( ( ) => this . updateAll ( ) ) ;
144+ this . _sub = this . gridstackItems ?. changes . subscribe ( ( ) => this . updateAll ( ) ) ;
148145 // ...and do this once at least unless we loaded children already
149146 if ( ! this . loaded ) this . updateAll ( ) ;
150147 this . hookEvents ( this . grid ) ;
151148 }
152149
153150 public ngOnDestroy ( ) : void {
154- delete this . ref ;
155- this . ngUnsubscribe . next ( ) ;
156- this . ngUnsubscribe . complete ( ) ;
157- this . grid ?. destroy ( ) ;
151+ this . unhookEvents ( this . _grid ) ;
152+ this . _sub ?. unsubscribe ( ) ;
153+ this . _grid ?. destroy ( ) ;
158154 delete this . _grid ;
159155 delete this . el . _gridComp ;
156+ delete this . container ;
157+ delete this . ref ;
160158 }
161159
162160 /**
@@ -199,6 +197,11 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
199197 . on ( 'resizestart' , ( event : Event , el : GridItemHTMLElement ) => this . resizeStartCB . emit ( { event, el} ) )
200198 . on ( 'resizestop' , ( event : Event , el : GridItemHTMLElement ) => this . resizeStopCB . emit ( { event, el} ) )
201199 }
200+
201+ private unhookEvents ( grid ?: GridStack ) {
202+ if ( ! grid ) return ;
203+ grid . off ( 'added change disable drag dragstart dragstop dropped enable removed resize resizestart resizestop' ) ;
204+ }
202205}
203206
204207/**
0 commit comments