import { Component, Inject } from '@angular/core'; import { MatDialogRef, MAT_DIALOG_DATA } from '@angular/material/dialog'; import { AlertService } from '../../common/services/alert/alert.service'; @Component({ selector: 'dr-save-form', templateUrl: './save-form.component.html', styleUrls: ['./save-form.component.scss'] }) export class SaveFormComponent { savedForm: any; result constructor( public dialogRef: MatDialogRef, @Inject(MAT_DIALOG_DATA) public data: any, private alertService: AlertService) { this.savedForm = data; } fnSaveAs(): void { const link = document.createElement('a'); link.setAttribute('href', 'data:octet/stream;charset=utf-8,' + encodeURIComponent(JSON.stringify(this.savedForm))); link.setAttribute('download', (this.savedForm.title || this.savedForm.name || ('Form_' + (new Date()).getTime().toString())) + '.json'); link.style.display = 'none'; document.body.appendChild(link); link.click(); document.body.removeChild(link); } fnSubmit(result): void { this.result = result; this.alertService.confirm('Form submitted!\n\nDownload Json?').subscribe(confirm => { if (confirm) { this.fnSaveAs(); } }); } }