Html File
<button mat-button (click) = "FileDownload">Download</button>
Anugular 4 Component Method
FileDownload()
{
this.filePath = "D:\SamplePDF.pdf";
document.loation.href = this.filePath;
}
Here, I want to download the local file when button click happens. I am not able to download the file. Please help.
PS: I am not able to access window.open() also as I am using angular 4 application.
Can you try this snippet
function downloadFunc(){
var anchor=document.createElement('a');
anchor.setAttribute('href','D:/SamplePDF.pdf');
anchor.setAttribute('download','');
document.body.appendChild(anchor);
anchor.click();
anchor.parentNode.removeChild(anchor);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With