点击复制指定内容
作者:互联网
项目为angualr4
1.在HTML中加一个input,(不可display:none)
```
<input type="text" name="copyInput" id="copyInput" [(ngModel)]="copyvalue" style="position: absolute;left:-100px;bottom:-100px">```
2.js代码
```
import { ElementRef } from '@angular/core'; public copyvalue = ''; public toCopy(item) { const input = this.el.nativeElement.querySelector('#copyInput'); this.copyvalue = item.url; input.value = item.url; input.select(); document.execCommand('Copy'); this._message.success('复制成功'); } constructor( private el: ElementRef ) {}```
(getElementByClassName 无效)
标签:el,指定,ElementRef,item,点击,复制,input,public,copyvalue 来源: https://www.cnblogs.com/zhuangcui/p/12132196.html