I am unable to find the answer anywhere, hopefully someone can help.
I have an Angular2 click event defined in the template, inside the table's cell:
<td (click)="click2Download()">fileName.txt</td>
In the typescript component, I need help to define a method click2Download() that would automatically start downloading the fileName.txt to client's browser. Note: file is on the same domain, e.g.:
http://example.com/fileName.txt
Any way of doing this with Angular2?
Have you tried: window.location.href = '...';
?
To force download of files you should use html attribute: <a target="_self" href="somefile.txt" download="somefile.txt">
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