gpt4 book ai didi

angular - 当以 5/6 Angular Angular 单击按钮时,如何从 url 下载文件

转载 作者:行者123 更新时间:2023-12-03 17:44:51 30 4
gpt4 key购买 nike

我有一个网址,例如: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/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com