I want to copy the link to the click button in AnuglarJS. I tried the code below, but I am stuck with this error:
This is mine button:
<button class="btn btn-info" ng-click="test2(\'' + decodeURI(data.name) + '\');" >copy</button>
this is my function in controller.js:
$scope.test2 = function (name)
{
var res = 'http://example.com?from=' + name;
var range = document.createRange();
range.selectNode(res);
window.getSelection().addRange(range);
try {
var successful = document.execCommand('copy');
var msg = successful ? 'successful' : 'unsuccessful';
console.log('Copy email command was ' + msg);
} catch (err) {
console.log('Oops, unable to copy');
}
window.getSelection().removeAllRanges();
}
press the button. I want to copy this link so that someone can help me how to do this.
source
share