From fcb3db19d7c651c4debcc4d1c5a508affeb87693 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sun, 24 Jul 2022 10:23:31 +0200 Subject: [PATCH] add: handle subscriptions in html export service --- src/app/html-export.service.ts | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/src/app/html-export.service.ts b/src/app/html-export.service.ts index 6c9b3ce..e15298c 100644 --- a/src/app/html-export.service.ts +++ b/src/app/html-export.service.ts @@ -1,7 +1,7 @@ -import { Injectable } from '@angular/core'; +import { Injectable, OnDestroy } from '@angular/core'; import { DomSanitizer, SafeUrl } from '@angular/platform-browser'; import { HttpClient } from '@angular/common/http'; -import { Observable } from 'rxjs'; +import { Observable, Subscription } from 'rxjs'; import { IFoodCard } from './ifood-card'; import { ITitle } from './ititle'; import { ISubtitle } from './isubtitle'; @@ -11,8 +11,9 @@ import { IFood } from './ifood'; providedIn: 'root' }) -export class HtmlExportService +export class HtmlExportService implements OnDestroy { + private subscriptions: Subscription[] = []; private cssExportContent: string = ""; private cssPrintExportContent: string = ""; @@ -20,11 +21,11 @@ export class HtmlExportService private httpclient: HttpClient) { let loadcss: Observable = this.loadCssFile("assets/htmlexport.css"); - loadcss.subscribe((content: any) => { - this.cssExportContent = content as string; }); + this.subscriptions.push(loadcss.subscribe((content: any) => { + this.cssExportContent = content as string; })); loadcss = this.loadCssFile("assets/htmlprintexport.css"); - loadcss.subscribe((content: any) => { - this.cssPrintExportContent = content as string; }); + this.subscriptions.push(loadcss.subscribe((content: any) => { + this.cssPrintExportContent = content as string; })); } public exportHtml(foodcard: IFoodCard): Observable @@ -144,4 +145,9 @@ export class HtmlExportService return divElement; } + + public ngOnDestroy(): void + { + this.subscriptions.forEach(s => s.unsubscribe()); + } } -- 2.39.5