]> gitweb.hhaalo.de Git - speisekarten-editor.git/commitdiff
add: handle subscriptions in html export service
authorBastian Dehn <hhaalo@arcor.de>
Sun, 24 Jul 2022 08:23:31 +0000 (10:23 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Sun, 24 Jul 2022 08:27:02 +0000 (10:27 +0200)
src/app/html-export.service.ts

index 6c9b3ce36ee654c042e8a4d9df133997cac5108c..e15298cec7018407ba1c41388c9bb0bc0dec142a 100644 (file)
@@ -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<SafeUrl> = 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<SafeUrl>
@@ -144,4 +145,9 @@ export class HtmlExportService
 
                return divElement;
        }
+
+       public ngOnDestroy(): void
+       {
+               this.subscriptions.forEach(s => s.unsubscribe());
+       }
 }