From 83e81e41b59ce09eb29a6ebb811d251cedb86691 Mon Sep 17 00:00:00 2001 From: Neil MacDougall Date: Mon, 23 Nov 2020 11:35:27 +0000 Subject: [PATCH] Fix ngDestroy bug on list view component (#4781) --- .../list-view/list-view.component.ts | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/frontend/packages/core/src/shared/components/list/list-generics/list-view/list-view.component.ts b/src/frontend/packages/core/src/shared/components/list/list-generics/list-view/list-view.component.ts index 9438e7ad30..a062e81bdb 100644 --- a/src/frontend/packages/core/src/shared/components/list/list-generics/list-view/list-view.component.ts +++ b/src/frontend/packages/core/src/shared/components/list/list-generics/list-view/list-view.component.ts @@ -1,4 +1,13 @@ -import { Component, ComponentFactoryResolver, ComponentRef, Injector, Input, OnInit, ViewChild } from '@angular/core'; +import { + Component, + ComponentFactoryResolver, + ComponentRef, + Injector, + Input, + OnDestroy, + OnInit, + ViewChild, +} from '@angular/core'; import { ListComponent } from '../../list.component'; import { IListConfig, ListConfig } from '../../list.component.types'; @@ -13,7 +22,7 @@ import { ListConfigProvider } from '../list-config-provider.types'; ListComponent ] }) -export class ListViewComponent implements OnInit { +export class ListViewComponent implements OnInit, OnDestroy { @Input() config: ListConfigProvider; @@ -28,9 +37,7 @@ export class ListViewComponent implements OnInit { ) { } ngOnInit() { - const componentFactory = this.componentFactoryResolver.resolveComponentFactory(ListComponent); - const viewContainerRef = this.listHost.viewContainerRef; this.componentRef = viewContainerRef.createComponent( componentFactory, @@ -46,10 +53,9 @@ export class ListViewComponent implements OnInit { }); } - ngDestroy() { + ngOnDestroy() { if (this.componentRef) { this.componentRef.destroy(); } } - }