]> gitweb.hhaalo.de Git - speisekarten-editor.git/commitdiff
change: export link click by button
authorBastian Dehn <hhaalo@arcor.de>
Fri, 10 Jun 2022 18:06:05 +0000 (20:06 +0200)
committerBastian Dehn <hhaalo@arcor.de>
Fri, 10 Jun 2022 18:06:05 +0000 (20:06 +0200)
src/app/app.component.html
src/app/app.component.ts

index b7e8c5577cc28b7a1416dde16192848082b92ea2..4c8ec2064ae340a43ad6885ebf73caee16d0d17a 100644 (file)
@@ -6,9 +6,10 @@
                type="button"
                id="exportJson"
                (click)="exportJson()">Export</button>
-       <a id="exportLink"
+       <a #exportLink
+               id="exportLink"
                [href]="downloadJsonHref"
-               [hidden]="downloadJsonHref === ''"
+               hidden="hidden"
                download="speisekarte.json">Download</a>
        <button class="button"
                type="button"
index 4a2a7e869749ec790b26dd918c9fab20c6ef2960..ceb2f78e4763d07596f321aa66bf6e6215027aa4 100644 (file)
@@ -1,4 +1,4 @@
-import { Component } from '@angular/core';
+import { Component, ViewChild, AfterViewChecked } from '@angular/core';
 import { SafeUrl } from '@angular/platform-browser';
 import { ITitle } from './ititle';
 import { ISubtitle } from './isubtitle';
@@ -12,8 +12,9 @@ import { JsonFileService } from './json-file.service';
        styleUrls: ['./app.component.css']
 })
 
-export class AppComponent
+export class AppComponent implements AfterViewChecked
 {
+       @ViewChild("exportLink")
        public foodcard: IFoodCard = { Titles: [] };
        public downloadJsonHref: SafeUrl = "";
 
@@ -40,5 +41,11 @@ export class AppComponent
                this.foodcard.Titles.push({ Title: "", Subtitles: [] });
        }
 
-
+       public ngAfterViewChecked()
+       {
+               if (this.downloadJsonHref !== "") {
+                       let link = document.getElementById("exportLink");
+                       link?.click();
+               }
+       }
 }