]> gitweb.hhaalo.de Git - speisekarten-editor.git/commitdiff
change: json export with observable
authorBastian Dehn <hhaalo@arcor.de>
Thu, 9 Jun 2022 20:19:15 +0000 (22:19 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Thu, 9 Jun 2022 20:19:15 +0000 (22:19 +0200)
src/app/app.component.html
src/app/app.component.ts
src/app/json-file.service.ts

index fcf353f691b0380f83f3418d7f22c8b0420e4832..b7e8c5577cc28b7a1416dde16192848082b92ea2 100644 (file)
@@ -6,8 +6,8 @@
                type="button"
                id="exportJson"
                (click)="exportJson()">Export</button>
-       <a [href]="downloadJsonHref"
-               id="exportLink"
+       <a id="exportLink"
+               [href]="downloadJsonHref"
                [hidden]="downloadJsonHref === ''"
                download="speisekarte.json">Download</a>
        <button class="button"
index 386cba1237340c446299e68635ae2b03bf6046b5..312aceb9f1e5dd603bf3901dff0f217286f383f5 100644 (file)
@@ -21,8 +21,10 @@ export class AppComponent
 
        public exportJson(): void
        {
-               this.downloadJsonHref = this.jsonFileService.exportJson(
-                       this.foodcard);
+               let observ = this.jsonFileService.exportJson(this.foodcard);
+               observ.subscribe((next) => {
+                       this.downloadJsonHref = next;
+               });
        }
 
        public fileEvent(event: any): void
@@ -30,7 +32,6 @@ export class AppComponent
                let importobserv = this.jsonFileService.importJson(event);
                importobserv.subscribe((next) => {
                        this.foodcard = next;
-                       console.log(next);
                });
        }
 
index f6f3d658022bedc0c0561e94a56240543b56d366..5ed1bc45ddedbfa327ff0d60fd687568d8436060 100644 (file)
@@ -11,11 +11,15 @@ export class JsonFileService
 {
        constructor(private sanitizer: DomSanitizer) {}
 
-       public exportJson(foodcard: IFoodCard): SafeUrl
+       public exportJson(foodcard: IFoodCard): Observable<string>
        {
-               let json = JSON.stringify(foodcard);
-               return this.sanitizer.bypassSecurityTrustUrl(
-                       "data:text/json;charset=UTF-8," + json);
+               let observ = new Observable<string>((observ) => {
+                       let json = JSON.stringify(foodcard);
+                       let result = <string> this.sanitizer.bypassSecurityTrustUrl("data:text/json;charset=UTF-8," + json);
+                       observ.next(result);
+               });
+
+               return observ
        }
 
        public importJson(event: any): Observable<IFoodCard>