API reference for Angular CDK clipboard
import {ClipboardModule} from '@angular/cdk/clipboard';
Services
Clipboard
A service for copying text to the clipboard.
Methods
beginCopy | |
---|---|
Prepares a string to be copied later. This is useful for large strings which take too long to successfully render and be copied in the same tick. The caller must call |
|
Parameters | |
text string
|
The string to copy. |
Returns | |
PendingCopy
|
the pending copy operation. |
copy | |
---|---|
Copies the provided text into the user's clipboard. |
|
Parameters | |
text string
|
The string to copy. |
Returns | |
boolean
|
Whether the operation was successful. |
Directives
CdkCopyToClipboard
Provides behavior for a button that when clicked copies content into user's clipboard.
Selector: [cdkCopyToClipboard]
Properties
Name | Description |
---|---|
@Input('cdkCopyToClipboardAttempts')
|
How many times to attempt to copy the text. This may be necessary for longer text, because the browser needs time to fill an intermediate textarea element and copy the content. |
@Input('cdkCopyToClipboard')
|
Content to be copied. |
@Output('cdkCopyToClipboardCopied')
|
Emits when some text is copied to the clipboard. The emitted value indicates whether copying was successful. |
Methods
copy | |
---|---|
Copies the current text to the clipboard. |
|
Parameters | |
attempts number = this.attempts
|
|
Classes
PendingCopy
A pending copy-to-clipboard operation.
The implementation of copying text to the clipboard modifies the DOM and forces a re-layout. This re-layout can take too long if the string is large, causing the execCommand('copy') to happen too long after the user clicked. This results in the browser refusing to copy. This object lets the re-layout happen in a separate tick from copying by providing a copy function that can be called later.
Destroy must be called when no longer in use, regardless of whether copy
is
called.
Methods
copy | |
---|---|
Finishes copying the text. |
|
Returns | |
boolean
|
|
destroy | |
---|---|
Cleans up DOM changes used to perform the copy operation. |
Interfaces
CdkCopyToClipboardConfig
Object that can be used to configure the default options for CdkCopyToClipboard
.
Properties
Name | Description |
---|---|
|
Default number of attempts to make when copying text to the clipboard. |
Constants
CDK_COPY_TO_CLIPBOARD_CONFIG
Injection token that can be used to provide the default options to CdkCopyToClipboard
.
const CDK_COPY_TO_CLIPBOARD_CONFIG: InjectionToken<CdkCopyToClipboardConfig>;