关于 angular + 页面复制粘贴功能


 <div class="user-token-content" *ngIf="tokenMark">
    <div class="token-card">
      <div class="token-card-content" id="copyInput"> {{tokenContent}} </div>
      <div class="token-card-control">
        <span nz-tooltip nzTitle="复制token" (click)="copyToken()">
          <i nz-icon type="copy" theme="outline"></i>
        </span>
        <nz-divider nzType="vertical"></nz-divider>
        <span nz-tooltip nzTitle="删除token">
          <a  nz-popconfirm nzTitle="是否删除当前token?" (nzOnConfirm)="confirm()" (nzOnCancel)="cancel()">
            <i nz-icon type="delete" theme="outline"></i>
          </a>
        </span>
      </div>
    </div>
  </div>
// 复制token
// .ts文件
copyToken() { const copyEl = this.elementRef.nativeElement.querySelector('#copyInput'); const range = document.createRange(); range.selectNode(copyEl); window.getSelection().removeAllRanges(); window.getSelection().addRange(range); document.execCommand('copy'); this.createMessage('success', '复制成功'); }
  • 效果
  •  


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM