Skip to content

Commit 3fecc2f

Browse files
author
Stan Bondi
committed
Add ability to copy interpolated text
1 parent 5cf0e49 commit 3fecc2f

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

demo/demo.html

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,19 @@
3333
<h1>Angular ZeroClipboard Demo</h1>
3434

3535
<form action="">
36-
<label for="">input: <input type="text" ng-model="input" id="input1"></label>
37-
<button ui-zeroclip zeroclip-copied="complete($event)" zeroclip-model="input" >Copy</button>
38-
<span ng-show="copied">Copied!</span>
36+
<div>
37+
<h1>Copy from input</h1>
38+
<label for="">input: <input type="text" ng-model="input" id="input1"></label>
39+
<button ui-zeroclip zeroclip-copied="complete($event)" zeroclip-model="input" >Copy</button>
40+
<span ng-show="copied">Copied!</span>
41+
</div>
3942

40-
<label for="">textarea: <textarea cols="30" rows="10" ui-zeroclip zeroclip-value-"textarea" ng-model="textarea"></textarea></label>
43+
<div>
44+
<h1>Copy interpolated text</h1>
45+
<span>This will copy: "This input text: {{ input }}"</span>
46+
<button ui-zeroclip zeroclip-copied="copiedText=true" zeroclip-text="This input text: {{ input }}" >Copy</button>
47+
<span ng-show="copiedText">Copied!</span>
48+
</div>
4149
</form>
4250

4351
</body>

src/angular-zeroclipboard.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ angular.module('zeroclipboard', [])
3535
scope: {
3636
onCopied: '&zeroclipCopied',
3737
client: '=?uiZeroclip',
38-
value: '=zeroclipModel'
38+
value: '=zeroclipModel',
39+
text: '@zeroclipText'
3940
},
4041
link: function(scope, element, attrs) {
4142
// config
@@ -47,6 +48,11 @@ angular.module('zeroclipboard', [])
4748
}
4849

4950
scope.$watch('value', function(v) {
51+
if (v == undefined) { return; }
52+
element.attr('data-clipboard-text', v);
53+
});
54+
55+
scope.$watch('text', function(v) {
5056
element.attr('data-clipboard-text', v);
5157
});
5258

0 commit comments

Comments
 (0)