Skip to content

Commit a81e134

Browse files
committed
Merge pull request #4 from wfairclough/master
Added support for an onError callback from Zeroclipboard.
2 parents 06569d6 + 3878fbe commit a81e134

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

demo/demo.html

+5-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
$scope.$watch('input', function(v) {
2626
$scope.copied = false
2727
});
28+
29+
$scope.clipError = function(e) {
30+
console.log('Error: ' + e.name + ' - ' + e.message);
31+
};
2832
}]);
2933
</script>
3034
</head>
@@ -36,7 +40,7 @@ <h1>Angular ZeroClipboard Demo</h1>
3640
<div>
3741
<h1>Copy from input</h1>
3842
<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>
43+
<button ui-zeroclip zeroclip-copied="complete($event)" zeroclip-on-error="clipError($event)" zeroclip-model="input" >Copy</button>
4044
<span ng-show="copied">Copied!</span>
4145
</div>
4246

src/angular-zeroclipboard.js

+10
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ angular.module('zeroclipboard', [])
3434
return {
3535
scope: {
3636
onCopied: '&zeroclipCopied',
37+
onError: '&?zeroclipOnError',
3738
client: '=?uiZeroclip',
3839
value: '=zeroclipModel',
3940
text: '@zeroclipText'
@@ -64,6 +65,15 @@ angular.module('zeroclipboard', [])
6465
});
6566
});
6667

68+
client.on('error', function(e) {
69+
if (scope.onError) {
70+
scope.$apply(function() {
71+
scope.onError({$event: e});
72+
});
73+
}
74+
ZeroClipboard.destroy();
75+
});
76+
6777
scope.$on('$destroy', function() {
6878
client.off('complete', _completeHnd);
6979
});

0 commit comments

Comments
 (0)