I want to copy link on click button in AnuglarJS. I have tried below code but I have stucked in this error:
This is my button :
<button class="btn btn-info" ng-click="test2(\'' + decodeURI(data.name) + '\');" >copy</button>
this my function in controller.js :
$scope.test2 = function (name)
{
var res = 'http://example.com?from=' + name;
var range = document.createRange();
range.selectNode(res); // here getting error
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();
}
click on button I want to copy this link any one can please help me how can do that.