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.execCommand('copy')
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.execCommand('copy')
Here is a simple code in case your text is not inside an input or textarea, but a div, or any other HTMLElement:
I was unable to use the
select()
command because it wasn't recognized by Angular. Hope this helps someone!Here is a way to achieve this without any external dependency or creating fake elements, only by using Clipboard API:
Can I use Clipboard API?
The code that you mentioned is the right way to do it and it can be done in Angular 2+ too.
I don't know what you accualy need to do, but if you, for example, have an input and a button:
then all you need to do is: