File

src/app/shared/components/paste-button/paste-button.component.ts

Metadata

Index

Properties
Methods
Outputs

Constructor

constructor()

Outputs

clipboard

Methods

Async pasteFromClipboard
pasteFromClipboard()
Returns : any

Properties

clipboard
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>

./paste-button.component.scss

ion-button {
    --border-radius: 50%;
    --padding-start: 8px;
    --padding-end: 8px;
    --padding-top: 8px;
    --padding-bottom: 8px;
  }
  
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""