Is there a way to copy text in clipboard (multi-browser) in Angular2 Typescript framework?
I find only sources of using Javascript, e.g.
document.exe
This is a simple pure Angular2 and javascript solution that doesn't require any libraries and which can be used in an angular component. You could turn it into a service or make it more generic if needed but this will establish the basic idea.
Currently browsers only allow text to be copied to the clipboard from the Selection in an or . This can implemented in div
(.html file)
Some texts
//(.ts file)
public copyToClipboard(){
var el = document.getElementById('inputId');
el.setAttribute('contenteditable','true');
el.focus();
document.execCommand('selectAll');
document.execCommand('copy');
el.setAttribute('contenteditable','false');
el.blur();
}