File
Index
Properties
|
|
Methods
|
|
Outputs
|
|
Methods
Async
pasteFromClipboard
|
pasteFromClipboard()
|
|
|
import { Component, output } from '@angular/core';
import { Clipboard } from '@capacitor/clipboard';
import { addIcons } from 'ionicons';
import { clipboardOutline } from 'ionicons/icons';
import { PasteButtonModule } from './paste-button.module';
@Component({
selector: 'app-paste-button',
templateUrl: './paste-button.component.html',
styleUrls: ['./paste-button.component.scss'],
standalone: true,
imports: [PasteButtonModule],
})
export class PasteButtonComponent {
clipboard = output<string>();
constructor() {
addIcons({ clipboardOutline });
}
// TODO: correctly implement error handling
async pasteFromClipboard() {
try {
const { value } = await Clipboard.read();
this.clipboard.emit(value);
} catch (error) {
throw Error(`Error reading from clipboard: ${error}`);
}
}
}
<ion-button
fill="clear"
shape="round"
aria-label="Paste authenticator key"
(click)="pasteFromClipboard()"
>
<ion-icon
color="medium"
slot="icon-only"
name="clipboard-outline"
aria-hidden="true"
></ion-icon>
</ion-button>
ion-button {
--border-radius: 50%;
--padding-start: 8px;
--padding-end: 8px;
--padding-top: 8px;
--padding-bottom: 8px;
}
Legend
Html element with directive