Skip to content

Commit

Permalink
Fix ngDestroy bug on list view component (#4781)
Browse files Browse the repository at this point in the history
  • Loading branch information
nwmac authored Nov 23, 2020
1 parent 48c4726 commit 83e81e4
Showing 1 changed file with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -13,7 +22,7 @@ import { ListConfigProvider } from '../list-config-provider.types';
ListComponent
]
})
export class ListViewComponent<T> implements OnInit {
export class ListViewComponent<T> implements OnInit, OnDestroy {

@Input() config: ListConfigProvider<T>;

Expand All @@ -28,9 +37,7 @@ export class ListViewComponent<T> implements OnInit {
) { }

ngOnInit() {

const componentFactory = this.componentFactoryResolver.resolveComponentFactory(ListComponent);

const viewContainerRef = this.listHost.viewContainerRef;
this.componentRef = viewContainerRef.createComponent(
componentFactory,
Expand All @@ -46,10 +53,9 @@ export class ListViewComponent<T> implements OnInit {
});
}

ngDestroy() {
ngOnDestroy() {
if (this.componentRef) {
this.componentRef.destroy();
}
}

}

0 comments on commit 83e81e4

Please sign in to comment.