From: Bastian Dehn Date: Sun, 24 Jul 2022 08:23:31 +0000 (+0200) Subject: add: handle subscriptions in html export service X-Git-Tag: v1.0.9^2~1 X-Git-Url: https://gitweb.hhaalo.de/?a=commitdiff_plain;h=fcb3db19d7c651c4debcc4d1c5a508affeb87693;p=speisekarten-editor.git add: handle subscriptions in html export service --- 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()); + } }