Skip to main content
cngx-src documentation

CngxCopyValue

DirectivePrimaryv0.1.0WCAG AA

projects/forms/input/copy-value.directive.ts

Import#

import { CngxCopyValue } from '@cngx/forms/input'

Description#

Clipboard copy behavior for input fields, tokens, API keys.

Place on a button or any clickable element. Copies value input or reads from a source element. Shows a copied signal for feedback (auto-resets after resetDelay).

<input #tokenInput readonly [value]="token()" />
<button [cngxCopyValue] [source]="tokenInput" #cp="cngxCopyValue">
  {{ cp.copied() ? 'Copied!' : 'Copy' }}
</button>

<!-- With explicit value -->
<button [cngxCopyValue]="apiKey()">Copy API Key</button>

https://cngxjs.github.io/cngx/examples/#/forms/input/utilities/copy-to-clipboard

Metadata#

Host#

Index#

Methods

Outputs

HostListeners

Inputs#

resetDelay#number | undefined
input()

Duration in ms to keep copied true after a successful copy. Falls back to global config.

source#HTMLInputElement | HTMLTextAreaElement | undefined
input()

Reference to the source element (fallback when value input not set).

value#string | undefined
input()

The value to copy. Falls back to source element's value if not provided.

default undefined, { alias: 'cngxCopyValue' }

Outputs#

didCopy#string
output()

Emitted after a successful copy.

Instance Properties#

copied#Signal
Readonly

true for resetDelay ms after a successful copy.

this.copiedState.asReadonly()
supported#unknown
Readonly

Whether the Clipboard API is available.

typeof navigator !== 'undefined' && !!navigator.clipboard

Methods#

copy#Promise
Async

Copies value to clipboard.

HostListeners#

EventHandler
(click)click()