import { Clipboard } from "@angular/cdk/clipboard";
实例化
constructor(private clipboard: Clipboard) {}
使用
html:
<button mat-button class="withdraw-btn" (click)="copyCode()">
<mat-icon inline>flip_to_front</mat-icon>
点击复制口令
</button>
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`;
}