在angular5/6中单击按钮时如何从URL下载文件 [英] How to download a file from a url when a button is clicked in angular5 / 6
本文介绍了在angular5/6中单击按钮时如何从URL下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个网址,例如:abc.net/files/test.ino要求是通过角度为5或6的按钮单击事件下载.INO文件.
I have a url for ex: abc.net/files/test.ino The requirement is to download an .INO file through a button click event in angular 5 or 6
推荐答案
您可以创建锚标记,以在按钮单击事件中下载文件
you can create an anchor tag to download the file on button click event
downloadMyFile(){
const link = document.createElement('a');
link.setAttribute('target', '_blank');
link.setAttribute('href', 'abc.net/files/test.ino');
link.setAttribute('download', `products.csv`);
document.body.appendChild(link);
link.click();
link.remove();
}
现在通过按钮调用此功能
now call this function from your button
<button (click)="downloadMyFile()">download File<button>
这篇关于在angular5/6中单击按钮时如何从URL下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文