ServiceOptional

WrClipboard

Copy text to the clipboard and read it back.

Installation

Import the class. This entry point has no stylesheet.

import { WrClipboard } from 'ngwr/clipboard';

Live demo

Copy writes the field; Paste reads the clipboard back.

available: false

Usage

private readonly clip = inject(WrClipboard);

const ok = await this.clip.write('Copied!'); // false when no write path worked
const text = await this.clip.read(); // null when unsupported or denied
const state = await this.clip.permission('read'); // 'granted' | 'denied' | 'prompt' | 'unsupported'

API

NameDescriptionTypeDefault
write(text)Write text. Falls back to execCommand outside a secure context. Resolves true on success.(text: string) => Promise<boolean>—
read()Read text. Resolves null when unsupported or denied.() => Promise<string | null>—
available()Whether any write path exists.() => boolean—
permission(name)Read or write permission. unsupported only when the Clipboard API is missing.(name: 'read' | 'write') => Promise<WrClipboardPermission>—

See also