MOBILE-4470 format-text: Destroy instances of external-content

main
Dani Palou 2024-05-22 16:18:02 +02:00
parent 47e9f07782
commit bb018c530f
1 changed files with 8 additions and 0 deletions

View File

@ -99,6 +99,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
protected emptyText = ''; protected emptyText = '';
protected domPromises: CoreCancellablePromise<void>[] = []; protected domPromises: CoreCancellablePromise<void>[] = [];
protected domElementPromise?: CoreCancellablePromise<void>; protected domElementPromise?: CoreCancellablePromise<void>;
protected externalContentInstances: CoreExternalContentDirective[] = [];
constructor( constructor(
element: ElementRef, element: ElementRef,
@ -145,6 +146,7 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
this.domElementPromise?.cancel(); this.domElementPromise?.cancel();
this.domPromises.forEach((promise) => { promise.cancel();}); this.domPromises.forEach((promise) => { promise.cancel();});
this.elementControllers.forEach(controller => controller.destroy()); this.elementControllers.forEach(controller => controller.destroy());
this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy());
} }
/** /**
@ -191,6 +193,8 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
extContent.ngAfterViewInit(); extContent.ngAfterViewInit();
this.externalContentInstances.push(extContent);
const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef); const changeDetectorRef = this.viewContainerRef.injector.get(ChangeDetectorRef);
changeDetectorRef.markForCheck(); changeDetectorRef.markForCheck();
@ -341,6 +345,10 @@ export class CoreFormatTextDirective implements OnChanges, OnDestroy, AsyncDirec
* Format contents and render. * Format contents and render.
*/ */
protected async formatAndRenderContents(): Promise<void> { protected async formatAndRenderContents(): Promise<void> {
// Destroy previous instances of external-content.
this.externalContentInstances.forEach(extContent => extContent.ngOnDestroy());
this.externalContentInstances = [];
if (!this.text) { if (!this.text) {
this.element.innerHTML = this.emptyText; // Remove current contents. this.element.innerHTML = this.emptyText; // Remove current contents.