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"
-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';
styleUrls: ['./app.component.css']
})
-export class AppComponent
+export class AppComponent implements AfterViewChecked
{
+ @ViewChild("exportLink")
public foodcard: IFoodCard = { Titles: [] };
public downloadJsonHref: SafeUrl = "";
this.foodcard.Titles.push({ Title: "", Subtitles: [] });
}
-
+ public ngAfterViewChecked()
+ {
+ if (this.downloadJsonHref !== "") {
+ let link = document.getElementById("exportLink");
+ link?.click();
+ }
+ }
}