Skip to content
This repository was archived by the owner on Jun 1, 2025. It is now read-only.

Commit fd0185e

Browse files
committed
fix: Row Detail preload comp should call destroy lifecycle
1 parent 578d667 commit fd0185e

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed
Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { Component } from '@angular/core';
1+
import { Component, OnDestroy } from '@angular/core';
22

33
@Component({
4-
template: `<h4>
5-
<i class="mdi mdi-sync mdi-spin-1s mdi-50px"></i>
6-
Loading...
7-
</h4>`,
4+
template: `<div class="container-fluid d-flex align-items-center" style="margin-top: 10px">
5+
<i class="mdi mdi-sync mdi-spin mdi-50px"></i>
6+
<h4>Loading...</h4>
7+
</div>`,
88
})
9-
export class RowDetailPreloadComponent {}
9+
export class RowDetailPreloadComponent implements OnDestroy {
10+
ngOnDestroy(): void {
11+
console.log('preload destroyed');
12+
}
13+
}

src/app/modules/angular-slickgrid/extensions/slickRowDetailView.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ export interface CreatedView {
3333
export class SlickRowDetailView extends UniversalSlickRowDetailView {
3434
rowDetailContainer!: ViewContainerRef;
3535
protected _preloadComponent: Type<object> | undefined;
36+
protected _preloadCompRef?: ComponentRef<any>;
3637
protected _views: CreatedView[] = [];
3738
protected _viewComponent!: Type<object>;
3839
protected _subscriptions: EventSubscription[] = [];
@@ -154,6 +155,9 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
154155

155156
if (this.onAsyncEndUpdate) {
156157
this.eventHandler.subscribe(this.onAsyncEndUpdate, (e, args) => {
158+
// destroy preload if exists
159+
this._preloadCompRef?.destroy();
160+
157161
// triggers after backend called "onAsyncResponse.notify()"
158162
this.renderViewModel(args?.item);
159163

@@ -269,10 +273,11 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
269273
`${PRELOAD_CONTAINER_PREFIX}`
270274
) as HTMLCollectionOf<HTMLElement>;
271275
if (this._preloadComponent && containerElements?.length >= 0) {
272-
this.angularUtilService.createAngularComponentAppendToDom(
276+
const preloadComp = this.angularUtilService.createAngularComponentAppendToDom(
273277
this._preloadComponent,
274278
containerElements[containerElements.length - 1]
275279
);
280+
this._preloadCompRef = preloadComp.componentRef;
276281
}
277282
}
278283

@@ -282,6 +287,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
282287
`${ROW_DETAIL_CONTAINER_PREFIX}${item[this.datasetIdPropName]}`
283288
) as HTMLCollectionOf<HTMLElement>;
284289
if (this._viewComponent && containerElements?.length > 0) {
290+
// render row detail
285291
const componentOutput = this.angularUtilService.createAngularComponentAppendToDom(
286292
this._viewComponent,
287293
containerElements[containerElements.length - 1],
@@ -312,9 +318,7 @@ export class SlickRowDetailView extends UniversalSlickRowDetailView {
312318
const compRef = expandedView?.componentRef;
313319
if (compRef) {
314320
this.appRef.detachView(compRef.hostView);
315-
if (compRef?.destroy) {
316-
compRef.destroy();
317-
}
321+
compRef?.destroy();
318322
return expandedView;
319323
}
320324
}

0 commit comments

Comments
 (0)