GenweiWu / Blog

个人技术能力提升
MIT License
4 stars 0 forks source link

angular4 复制到剪切板 #49

Closed GenweiWu closed 6 years ago

GenweiWu commented 6 years ago

ngx-clipboard

为了适配angular4,需要使用较低版本的ngx-clipboard,此次使用的版本:

"ngx-clipboard": "8.1.1"

GenweiWu commented 6 years ago

使用方法

xxx.module.ts


import { ClipboardModule } from 'ngx-clipboard';

imports:[ClipboardModule]


> xxx.component.ts
```ts
import { Component, OnInit, Renderer } from '@angular/core';
import { ClipboardService } from 'ngx-clipboard'

 constructor(
    private clipboardService: ClipboardService,
    private renderer: Renderer,
  ) { }

 copyContent(){
    this.clipboardService.copyFromContent("copycontentXXX", this.renderer); 
 }
GenweiWu commented 6 years ago

参考

https://segmentfault.com/a/1190000010326100