有没有办法在 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');
}
Run Code Online (Sandbox Code Playgroud)
成分:
<button class="btn btn-primary btn-sm" (click)="callServiceToCopy()">Copy</button>
Run Code Online (Sandbox Code Playgroud)
小智 0
copyToClipboard(id:string): void {
const from = document.getElementById(id);
const range = document.createRange();
window.getSelection().removeAllRanges();
range.selectNode(from);
window.getSelection().addRange(range);
document.execCommand('copy');
window.getSelection().removeAllRanges();
}
<button (click)="copyToClipboard('<B>This is an important message<\/B>\n These are the details')">Copy text</button>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3677 次 |
| 最近记录: |