0

Is it possible to download a file (e.g. Power point presentation) through a link when an igx Button is clicked? I could not find any related topic to my question.

Here is my example code:

  <button igxButton="raised" (click)="downloadFile()" class="downloadBtn">
    Download File
  </button>

and the function:

downloadFile() {
   let exampleLink = "https://downloadexamplefile.com/fileid123"
  }

Thank you!

Konstantin Dinev
  • 34,219
  • 14
  • 75
  • 100
yooy
  • 11
  • 5

1 Answers1

2

This functionality is not specific to the igxButton. The button may be a tirgger for the download action, although the actual action is something that you will need to handle.

An example would be creating a Service and specifying the responseType option that upon GET request can return a blob representing the downloaded file. Then you can call this service, subscribe to the corresponding observable, and eventually save the file upon igxButton click

Example: https://www.thecodehubs.com/download-file-with-httpclient-in-angular/

Zdravko Kolev
  • 1,569
  • 14
  • 20
  • 2
    Yes, thank you, I fixed it. I opened the URL with the file for download through window.open(https://www.downloadURL.com"); – yooy Feb 08 '22 at 10:56