ngx-clipboard . . - ClipboardService. ,
import { ClipboardService } from 'ngx-clipboard'
constructor(private _clipboardService: ClipboardService){
...
}
copy(text: string){
this._clipboardService.copyFromContent(text)
}
. , . Angular 4, .
@ViewChild, .
HTML:
<textarea name="copyText" #copyText id="" style="opacity: 0;height: 0;"></textarea>
:
@ViewChild('copyText', { read: ElementRef }) copyText: ElementRef;
copyText() {
const element = this.copyText.nativeElement;
element.value = 'some text';
element.focus();
element.select();
document.execCommand('copy');
}
JavaScript- Angular @ViewChild.
source
share