我有一个网址,例如:abc.net/files/test.ino
要求是通过 angular 5 或 6 的按钮单击事件下载 .INO 文件
最佳答案
您可以创建一个 anchor 标签来下载按钮点击事件上的文件
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();
}
现在从你的按钮调用这个函数
<button (click)="downloadMyFile()">download File<button>
关于angular - 当以 5/6 Angular Angular 单击按钮时,如何从 url 下载文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55587921/