DirectiveOptional

wrCopyToClipboard

Copy a string to the clipboard when the element is clicked.

Installation

Import the class, and @use the entry point in your global styles: without it the component renders unstyled.

import { Component } from '@angular/core';
import { WrButton } from 'ngwr/button';
import { WrCopyToClipboard } from 'ngwr/directives';

@Component({ imports: [WrButton, WrCopyToClipboard] })
export class MyComponent {}

Usage

(copied) fires once the text is on the clipboard. A refusal emits (copyFailed).

<button [wrCopyToClipboard]="value" (copied)="toast('Copied!')">Copy</button>

API

NameDescriptionTypeDefault
[wrCopyToClipboard]requiredThe string copied on host click. Required.string—
(copied)The text that reached the clipboard.string—
(copyFailed)What the write threw, such as a denied permission.unknown—

See also