From 8b57610be4ab38685b43f4a2a806876a8bc50fa2 Mon Sep 17 00:00:00 2001 From: Giuseppe Digilio Date: Fri, 19 Feb 2021 12:09:12 +0100 Subject: [PATCH] [CST-3620] Add component destroy on reload of loaded object within the listable-object-component-loader.component.ts --- .../listable-object-component-loader.component.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts index 9fc27d65bf..ff85c59885 100644 --- a/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts +++ b/src/app/shared/object-collection/shared/listable-object/listable-object-component-loader.component.ts @@ -1,4 +1,4 @@ -import { Component, ComponentFactoryResolver, Input, OnDestroy, OnInit, ViewChild, ElementRef } from '@angular/core'; +import { Component, ComponentFactoryResolver, ElementRef, Input, OnDestroy, OnInit, ViewChild } from '@angular/core'; import { ListableObject } from '../listable-object.model'; import { ViewMode } from '../../../../core/shared/view-mode.model'; import { Context } from '../../../../core/shared/context.model'; @@ -9,6 +9,7 @@ import { CollectionElementLinkType } from '../../collection-element-link.type'; import { hasValue } from '../../../empty.util'; import { Subscription } from 'rxjs/internal/Subscription'; import { DSpaceObject } from '../../../../core/shared/dspace-object.model'; +import { take } from 'rxjs/operators'; @Component({ selector: 'ds-listable-object-component-loader', @@ -135,13 +136,14 @@ export class ListableObjectComponentLoaderComponent implements OnInit, OnDestroy (componentRef.instance as any).value = this.value; if ((componentRef.instance as any).reloadedObject) { - this.subs.push((componentRef.instance as any).reloadedObject.subscribe((reloadedObject: DSpaceObject) => { + (componentRef.instance as any).reloadedObject.pipe(take(1)).subscribe((reloadedObject: DSpaceObject) => { if (reloadedObject) { + componentRef.destroy(); console.log('Reloaded Object from/to', this.object, reloadedObject); this.object = reloadedObject; this.instantiateComponent(reloadedObject); } - })); + }); } }