angular - navigator.clipboard.readText() 的等效代码是什么?
问题描述
navigator.clipboard.readText()
.then(text => {
// `text` contains the text read from the clipboard
})
.catch(err => {
// maybe user didn't grant access to read from clipboard
console.log('Something went wrong', err);
});
我需要从剪贴板读取按钮单击角度
如何做到这一点?
解决方案
通过您的问题,我看到您遗漏了一些重要的东西。您的 Angular 应用程序是用typescript编写的,即:
JavaScript 的类型化超集,可编译为纯 JavaScript
这意味着您提到的剪贴板 API可以在 Angular 中使用!正如您在这个使用您的代码的演示中看到的那样。
当前 typescript 的navigator
类型为DefinedTyped,但不幸的是它仍然不包含剪贴板 API,因为它仍然是非标准 DOM API,正如您在这个 git 已关闭问题中所见 - Missing 'Navigator.clipboard' (clipboard asynchronous API)
推荐阅读
- angular - 无法创建带有标题行的表格并将动态数据添加到 ckeditor 5 和 angular 9 中的标题和数据单元格
- lisp - 获得拉伸的测量值
- javascript - 请告诉我,如何创建一个将对象的所有数字属性乘以 2 的函数
- algorithm - 计算非负整数平面二维矩阵上闭环数量的并行算法
- c# - foreach 中的模态为每个模态返回相同的数据
- r - 我正在预测未来几年的人口,如何将预测数据附加到我的原始数据集,然后绘制完整的数据集?
- javafx - 应用程序徽标的不同大小 - JavaFX
- jquery - Husky 和 lint-staged 无法运行 gulp 命令
- node.js - DynamoDB 有没有办法生成唯一的 autoID?
- excel - Power Query 表标题删除分隔符前的文本