From 7abf37cbeabef9379290a2097f7315cd615751cb Mon Sep 17 00:00:00 2001 From: Alexandre Vryghem Date: Sat, 24 Feb 2024 14:20:35 +0100 Subject: [PATCH] Fixed some components not destroying their ViewContainerRef --- .../item-edit-bitstream-bundle.component.ts | 9 +++++++-- .../item-edit-bitstream-drag-handle.component.ts | 8 ++++++-- .../item-edit-bitstream/item-edit-bitstream.component.ts | 8 ++++++-- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts index eb05d5e74f..6a4f1968ae 100644 --- a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts +++ b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-bundle/item-edit-bitstream-bundle.component.ts @@ -1,4 +1,4 @@ -import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewContainerRef } from '@angular/core'; +import { Component, EventEmitter, Input, OnInit, Output, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core'; import { Bundle } from '../../../../core/shared/bundle.model'; import { Item } from '../../../../core/shared/item.model'; import { ResponsiveColumnSizes } from '../../../../shared/responsive-table-sizes/responsive-column-sizes'; @@ -15,7 +15,7 @@ import { getItemPageRoute } from '../../../item-page-routing-paths'; * Creates an embedded view of the contents. This is to ensure the table structure won't break. * (which means it'll be added to the parents html without a wrapping ds-item-edit-bitstream-bundle element) */ -export class ItemEditBitstreamBundleComponent implements OnInit { +export class ItemEditBitstreamBundleComponent implements OnInit, OnDestroy { /** * The view on the bundle information and bitstreams @@ -63,4 +63,9 @@ export class ItemEditBitstreamBundleComponent implements OnInit { this.viewContainerRef.createEmbeddedView(this.bundleView); this.itemPageRoute = getItemPageRoute(this.item); } + + ngOnDestroy(): void { + this.viewContainerRef.clear(); + } + } diff --git a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component.ts b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component.ts index e5cb9ba403..d9c9a8f34a 100644 --- a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component.ts +++ b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream-drag-handle/item-edit-bitstream-drag-handle.component.ts @@ -1,4 +1,4 @@ -import { Component, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; +import { Component, OnInit, ViewChild, ViewContainerRef, OnDestroy } from '@angular/core'; @Component({ selector: 'ds-item-edit-bitstream-drag-handle', @@ -10,7 +10,7 @@ import { Component, OnInit, ViewChild, ViewContainerRef } from '@angular/core'; * Creates an embedded view of the contents * (which means it'll be added to the parents html without a wrapping ds-item-edit-bitstream-drag-handle element) */ -export class ItemEditBitstreamDragHandleComponent implements OnInit { +export class ItemEditBitstreamDragHandleComponent implements OnInit, OnDestroy { /** * The view on the drag-handle */ @@ -23,4 +23,8 @@ export class ItemEditBitstreamDragHandleComponent implements OnInit { this.viewContainerRef.createEmbeddedView(this.handleView); } + ngOnDestroy(): void { + this.viewContainerRef.clear(); + } + } diff --git a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.ts b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.ts index d7fcc0cb76..1d1644b89a 100644 --- a/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.ts +++ b/src/app/item-page/edit-item-page/item-bitstreams/item-edit-bitstream/item-edit-bitstream.component.ts @@ -1,4 +1,4 @@ -import { Component, Input, OnChanges, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core'; +import { Component, Input, OnChanges, OnDestroy, OnInit, SimpleChanges, ViewChild, ViewContainerRef } from '@angular/core'; import { Bitstream } from '../../../../core/shared/bitstream.model'; import { cloneDeep } from 'lodash'; import { ObjectUpdatesService } from '../../../../core/data/object-updates/object-updates.service'; @@ -21,7 +21,7 @@ import { getBitstreamDownloadRoute } from '../../../../app-routing-paths'; * Creates an embedded view of the contents * (which means it'll be added to the parents html without a wrapping ds-item-edit-bitstream element) */ -export class ItemEditBitstreamComponent implements OnChanges, OnInit { +export class ItemEditBitstreamComponent implements OnChanges, OnDestroy, OnInit { /** * The view on the bitstream @@ -72,6 +72,10 @@ export class ItemEditBitstreamComponent implements OnChanges, OnInit { this.viewContainerRef.createEmbeddedView(this.bitstreamView); } + ngOnDestroy(): void { + this.viewContainerRef.clear(); + } + /** * Update the current bitstream and its format on changes * @param changes