项目为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 无效)