有没有办法在 Angular 中将 html 复制到剪贴板?
我正在使用 ngx-clipboard,并尝试格式化复制的文本(即使用粗体、项目符号)
.ts
constructor(private _clipboardService: ClipboardService) {}
callServiceToCopy() {
this._clipboardService.copyFromContent('<B>This is an important message<\/B>\n These are the details');
}
成分:
<button class="btn btn-primary btn-sm" (click)="callServiceToCopy()">Copy</button>
堆栈闪电战:https://stackblitz.com/edit/github-ar12tp-irzz84 https://stackblitz.com/edit/github-ar12tp-irzz84
您现在可以使用这个 api:
const type = "text/html";
const blob = new Blob([ '<h1>Your <b>html</b> content here</h1>' ], { type });
const data = [new ClipboardItem({ [type]: blob })];
navigator.clipboard.write(data);
细节:https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write https://developer.mozilla.org/en-US/docs/Web/API/Clipboard/write
在此处检查浏览器兼容性:https://caniuse.com/mdn-api_clipboard_write https://caniuse.com/mdn-api_clipboard_write
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)