File
Index
Properties
|
|
Methods
|
|
Inputs
|
|
Methods
Async
copyToClipboard
|
copyToClipboard($event: any, string: string)
|
|
Copy token to system clipboard.
Parameters :
Name |
Type |
Optional |
$event |
any
|
No
|
string |
string
|
No
|
|
clicked
|
Default value : signal(false)
|
|
import { Component, input, signal } from '@angular/core';
import { NgIf } from '@angular/common';
import { Clipboard } from '@capacitor/clipboard';
import { timer } from 'rxjs';
import { IonButton, IonIcon } from '@ionic/angular/standalone';
import { addIcons } from 'ionicons';
import { copyOutline, clipboardOutline } from 'ionicons/icons';
import { TokenPipe } from '../../pipes/token.pipe';
@Component({
selector: 'app-copy-token',
templateUrl: './copy-token.component.html',
styleUrls: ['./copy-token.component.scss'],
standalone: true,
imports: [IonButton, IonIcon, NgIf, TokenPipe],
})
export class CopyTokenComponent {
clicked = signal(false);
value = input.required<string>();
constructor() {
addIcons({ copyOutline, clipboardOutline });
}
/**
* Copy token to system clipboard.
*
* @param $event
* @param string
*/
async copyToClipboard($event: any, string: string) {
try {
this.clicked.set(true);
timer(1000).subscribe(() => this.clicked.set(false));
await Clipboard.write({ string });
} catch (error) {
throw Error(`${error}`);
}
}
}
<ion-button
shape="round"
color="secondary"
(click)="copyToClipboard($event, value())"
*ngIf="!clicked()"
>
<ion-icon name="copy-outline" slot="start"></ion-icon>
{{ value() | token }}
</ion-button>
<ion-button
shape="round"
fill="outline"
color="secondary"
[disabled]="true"
*ngIf="clicked()"
>
<ion-icon name="clipboard-outline" slot="start"></ion-icon>
Copied!
</ion-button>
ion-button {
width: 140px;
}
Legend
Html element with directive