自存angular 复制功能 使用angular material design Clipboard cdk

import { Clipboard } from "@angular/cdk/clipboard";

实例化

  constructor(private clipboard: Clipboard) {}

使用

参考angular clipboard cdk

html:

              

ts :

  copyCode() {
    const id = "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(
      /[xy]/g,
      function (c) {
        var r = (Math.random() * 16) | 0,
          v = c == "x" ? r : (r & 0x3) | 0x8;
        return v.toString(16);
      }
    );
    this.clipboard.copy(id);
    alert(`Id "${id}" is generated and copied to the clipboard`);
  }
  copy(value) {
    return `${value}\n\ncopied from timdeschryver.dev`;
  }

你可能感兴趣的:(angular.js,javascript,前端)