How do I copy to clipboard in Angular 2 Typescript?

前端 未结 10 1071
-上瘾入骨i
-上瘾入骨i 2020-12-03 06:45

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         


        
10条回答
  •  北荒
    北荒 (楼主)
    2020-12-03 07:27

    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
提交回复
热议问题