0

I'm trying to find a way to download a file using a location/link. window.open(location) opens another tab so I'm not keen on using that.

I know there's already a <a href='location' download>Download</a> implementation but it does not seem to be doable right now since I'm using a custom component so I'm looking for an option like that in JavaScript. Is there a way?

<custom-option (buttonClickEmitter)="downloadList(location)" [label]="translations.download"></custom-option>

File type is only CSV.

Thank you!

mengmeng
  • 1,266
  • 2
  • 22
  • 46

1 Answers1

0

Try FileSaver js library

it helps you to save any files directly from a HTTP response

https://github.com/eligrey/FileSaver.js/

import { saveAs } from 'file-saver';

FileSaver saveAs(Blob/File/Url, optional DOMString filename, optional Object { autoBom })
Jeba Prince
  • 1,669
  • 4
  • 22
  • 41