if you do not want to add a new library to your project, and you create it yourself, here is a simple and simple solution:
Note: I created it with promise functionality (which is surprising)
here is CopyToClipboard.js module file
angular.module('CopyToClipboard', []) .controller('CopyToClipboardController', function () { }) .provider('$copyToClipboard', [function () { this.$get = ['$q', '$window', function ($q, $window) { var body = angular.element($window.document.body); var textarea = angular.element('<textarea/>'); textarea.css({ position: 'fixed', opacity: '0' }); return { copy: function (stringToCopy) { var deferred = $q.defer(); deferred.notify("copying the text to clipboard"); textarea.val(stringToCopy); body.append(textarea); textarea[0].select(); try { var successful = $window.document.execCommand('copy'); if (!successful) throw successful; deferred.resolve(successful); } catch (err) { deferred.reject(err);
what is he thanks https://gist.github.com/JustMaier/6ef7788709d675bd8230
now you can use it
angular.module('somthing') .controller('somthingController', function ($scope, $copyToClipboard) { // you are free to do what you want $scope.copyHrefToClipboard = function() { $copyToClipboard.copy(/*string to be coppied*/$scope.shareLinkInfo.url).then(function () { //show some notification }); }; }
and finally HTML
<i class="fa fa-clipboard" data-ng-click="copyHrefToClipboard($event)"></i>
hope it saves you time
source share