angular - Typescript Angular 7,复制到剪贴板
问题描述
我想制作一个非常简单的输入组,其中包含一个禁用的输入和一个将输入值复制到剪贴板的按钮。当它被复制时,我希望弹出一条小消息说它是。
有什么好的方法可以做到这一点吗?
这种方法似乎不起作用,它看起来像一个快速修复,看起来不太好。
copyInputMessage(inputElement){
inputElement.select();
document.execCommand('copy');
inputElement.setSelectionRange(0, 0);
}
我得到的 html 看起来像这样 atm:
<div class="input-group">
<input class="form-control" disabled value="TextToBeCopied" #inputToBeCopied/>
<button (click)="copyInputMessage(inputToBeCopied)" value="click to copy">COPY</button>
</div>
我只能找到非常奇怪的解决方案,必须有更简单的方法?
我已经看到了已经存在的解决方案,没有人适合我,也不适合我的问题。
解决方案
推荐阅读
- cuda - 如何与多个块和线程共享单个数组?
- graphql - 将 GraphQL 文件中的片段导入另一个 GraphQL 文件不起作用
- php - 尝试从命名空间“knp\Bundle\PaginatorBundle”加载类“knpPaginatorBundle”。您是否忘记了另一个命名空间的“使用”语句?
- r - 特征(A)中的错误:'x'中的无限或缺失值
- amazon-web-services - 在路径样式弃用后,存储桶名称中是否仍允许使用句点(。)
- jenkins - maven 多模块项目 - 在子模块中提交不会触发 jenkins 作业
- c++ - 如何在 C++ 中返回 foreach 循环的值?
- java - 我们如何根据不完整的名称找到项目?
- jvm - 在tomcat目录下创建了许多文件jvm.pid.bkp
- java - 如何保持下拉菜单处于活动状态并单击 selenium 中 iframe 下可用的子菜单?