1
1
The clipboard package provides helpers for working with the system clipboard.
2
2
3
- ## ` cdkCopyToClipboard ` directive
3
+ ### Click an element to copy
4
4
5
- The ` cdkCopyToClipboard ` directive can be used to easily add copy-on-click
6
- functionality to an existing element. The directive selector doubles as an
7
- ` @Input() ` for the text to be copied.
5
+ The ` cdkCopyToClipboard ` directive can be used to easily add copy-on-click functionality to an
6
+ existing element. The directive selector doubles as an ` @Input() ` for the text to be copied.
8
7
9
8
``` html
10
9
<img src =" avatar.jpg" alt =" Hero avatar" [cdkCopyToClipboard] =" getShortBio()" >
11
10
```
12
11
13
12
<!-- example(cdk-clipboard-overview) -->
14
13
15
- ## ` Clipboard ` service
14
+ ### Programmatically copy a string
16
15
17
- The ` Clipboard ` service copies text to the
18
- user's clipboard. It has two methods: ` copy ` and ` beginCopy ` . For cases where
19
- you are copying a relatively small amount of text, you can call ` copy ` directly
20
- to place it on the clipboard.
16
+ The ` Clipboard ` service copies text to the user's clipboard. It has two methods: ` copy ` and
17
+ ` beginCopy ` . For cases where you are copying a relatively small amount of text, you can call ` copy `
18
+ directly to place it on the clipboard.
21
19
22
20
``` typescript
23
21
class HeroProfile {
@@ -29,13 +27,11 @@ class HeroProfile {
29
27
}
30
28
```
31
29
32
- However, for longer text the browser needs time to fill an intermediate
33
- textarea element and copy the content. Directly calling ` copy ` may fail
34
- in this case, so you can pre-load the text by calling ` beginCopy ` . This method
35
- returns a ` PendingCopy ` object that has a ` copy ` method to finish copying the
36
- text that was buffered. Please note, if you call ` beginCopy ` , you must
37
- clean up the ` PendingCopy ` object by calling ` destroy ` on it after you are
38
- finished.
30
+ However, for longer text the browser needs time to fill an intermediate textarea element and copy
31
+ the content. Directly calling ` copy ` may fail in this case, so you can pre-load the text by calling
32
+ ` beginCopy ` . This method returns a ` PendingCopy ` object that has a ` copy ` method to finish copying
33
+ the text that was buffered. Please note, if you call ` beginCopy ` , you must clean up the
34
+ ` PendingCopy ` object by calling ` destroy ` on it after you are finished.
39
35
40
36
``` typescript
41
37
class HeroProfile {
@@ -54,7 +50,7 @@ class HeroProfile {
54
50
// Remember to destroy when you're done!
55
51
pending .destroy ();
56
52
}
57
- }
53
+ };
58
54
setTimeout (attempt );
59
55
}
60
56
}
0 commit comments