It was just then, I was expecting
constructor(private sanitizer: DomSanitizer){} generateDownloadJsonUri() { var theJSON = JSON.stringify(this.resJsonResponse); var uri = this.sanitizer.bypassSecurityTrustUrl("data:text/json;charset=UTF-8," + encodeURIComponent(theJSON)); this.downloadJsonHref = uri; }
in the template
<a class="btn btn-clear" title="Download JSON" [href]="downloadJsonHref" download="download.json"></a>
source share