5
5
6
6
import { AfterContentInit , Component , ContentChildren , ElementRef , EventEmitter , Input ,
7
7
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' ;
10
9
import { GridHTMLElement , GridItemHTMLElement , GridStack , GridStackNode , GridStackOptions , GridStackWidget } from 'gridstack' ;
11
10
12
11
import { GridItemCompHTMLElement , GridstackItemComponent } from './gridstack-item.component' ;
@@ -119,8 +118,8 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
119
118
120
119
private _options ?: GridStackOptions ;
121
120
private _grid ?: GridStack ;
121
+ private _sub : Subscription | undefined ;
122
122
private loaded ?: boolean ;
123
- private ngUnsubscribe : Subject < void > = new Subject ( ) ;
124
123
125
124
constructor (
126
125
// private readonly zone: NgZone,
@@ -142,21 +141,20 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
142
141
/** wait until after all DOM is ready to init gridstack children (after angular ngFor and sub-components run first) */
143
142
public ngAfterContentInit ( ) : void {
144
143
// 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 ( ) ) ;
148
145
// ...and do this once at least unless we loaded children already
149
146
if ( ! this . loaded ) this . updateAll ( ) ;
150
147
this . hookEvents ( this . grid ) ;
151
148
}
152
149
153
150
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 ( ) ;
158
154
delete this . _grid ;
159
155
delete this . el . _gridComp ;
156
+ delete this . container ;
157
+ delete this . ref ;
160
158
}
161
159
162
160
/**
@@ -199,6 +197,11 @@ export class GridstackComponent implements OnInit, AfterContentInit, OnDestroy {
199
197
. on ( 'resizestart' , ( event : Event , el : GridItemHTMLElement ) => this . resizeStartCB . emit ( { event, el} ) )
200
198
. on ( 'resizestop' , ( event : Event , el : GridItemHTMLElement ) => this . resizeStopCB . emit ( { event, el} ) )
201
199
}
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
+ }
202
205
}
203
206
204
207
/**
0 commit comments