Clipboard ​

Reactive wrapper around the Clipboard API. Read and write clipboard content with Angular signals.

Secure Context Required

This feature is available only in secure contexts (HTTPS) or potentially trustworthy origins (such as localhost or 127.0.0.1). Regular http:// URLs will not work in most browsers.

Loading demo...

Usage ​

angular-ts
import { Component, signal } from '@angular/core';
import { clipboard } from '@signality/core';

@Component({
  template: `
    <input [(ngModel)]="textToCopy" />
    <button (click)="cb.copy(textToCopy())">Copy</button>
    <button (click)="cb.paste()">Paste</button>
    <p>Clipboard: {{ cb.text() }}</p>
  `,
})
export class ClipboardDemo {
  readonly cb = clipboard(); 
  readonly textToCopy = signal('');
}

Parameters ​

ParameterTypeDescription
optionsClipboardOptionsOptional configuration (see Options below)

Options ​

OptionTypeDefaultDescription
copiedDurationMaybeSignal<number>1500How long copied stays true after copy (ms)
injectorInjector-Optional injector for DI context

Return Value ​

The clipboard() function returns a ClipboardRef object:

PropertyTypeDescription
textSignal<string>Current clipboard text content
copiedSignal<boolean>Whether content was recently copied (resets after timeout)
isSupportedSignal<boolean>Whether Clipboard API is supported
copy(text: string) => Promise<void>Copy text to clipboard
paste() => Promise<string>Read text from clipboard

Examples ​

Copy button with feedback ​

angular-ts
import { Component, input } from '@angular/core';
import { clipboard } from '@signality/core';

@Component({
  selector: 'copy-button',
  template: `
    <button 
      (click)="copyCode()" 
      [class.copied]="cb.copied()"
    >
      {{ cb.copied() ? '✓ Copied!' : 'Copy' }}
    </button>
  `,
})
export class CopyButton {
  readonly code = input.required<string>();
  readonly duration = input(2000);
  readonly cb = clipboard({ copiedDuration: this.duration }); 
  
  async copyCode() {
    await this.cb.copy(this.code());
  }
}

Paste from clipboard ​

angular-ts
import { Component } from '@angular/core';
import { clipboard } from '@signality/core';

@Component({
  template: `
    <button (click)="cb.paste()">Paste from clipboard</button>
    <pre>{{ cb.text() }}</pre>
  `,
})
export class PasteDemo {
  readonly cb = clipboard();
}

Browser Compatibility ​

The Clipboard API has limited browser support and requires a secure context (HTTPS). Always check isSupported() before using clipboard functionality (see Browser API support detection):

angular-html
@if (cb.isSupported()) {
  <button (click)="cb.copy(text)">Copy</button>
  <button (click)="cb.paste()">Paste</button>
} @else {
  <p>Clipboard API is not available in this browser</p>
}

For detailed browser support information, see Can I use: Clipboard API.

SSR Compatibility ​

On the server, signals initialize with safe defaults:

  • text → ''
  • copied → false
  • isSupported → false
  • copy, paste → no-op async functions

Type Definitions ​

typescript
interface ClipboardOptions extends WithInjector {
  readonly copiedDuration?: MaybeSignal<number>;
}

interface ClipboardRef {
  readonly text: Signal<string>;
  readonly copied: Signal<boolean>;
  readonly isSupported: Signal<boolean>;
  readonly copy: (text: string) => Promise<void>;
  readonly paste: () => Promise<string>;
}

function clipboard(options?: ClipboardOptions): ClipboardRef;
Edit this page on GitHub Last updated: Mar 19, 2026, 23:28:23