ng-clip copy to clipboard is not working

2019-04-08 08:21发布

I'm implementing the ng-clip using some tutorials. i'm doing it as it is in the tutorial but it's not working. i included Zeroclipboard.min.js, angular.js, ngClip.js

Html looks like..

    <div ng-app="clip">
        <button clip-copy="getTextToCopy()">Copy</button>
    </div>

Script looks like..

    angular.module('clip', ['ngClipboard']);

    function Main($scope) {
        $scope.getTextToCopy = function() {
    return "ngClip is awesome!";
        }

    $scope.doSomething = function () {
    console.log("NgClip...");
        }
    }

can anyone suggest me where i went wrong! Thanks.

1条回答
ら.Afraid
2楼-- · 2019-04-08 08:51

I faced the same problem; the fix is to include the js files as shown below and Run the web page on server. Create a folder in tomcat>>webapps and paste the webpage there. Now view the page at url

http://localhost:8080/(folderName)/(pageName).html
 <script src="http://asafdav.github.io/ng-csv/javascripts/ngClip.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/zeroclipboard/1.1.7/ZeroClipboard.min.js"></script>
<script>
angular.module('clip', ['ngClipboard']);

function Main($scope) {
    $scope.getTextToCopy = function() {
        return "ngClip is awesome!";
    }
    $scope.doSomething = function () {
        console.log("NgClip...");
    }
}
</script>

<html>
<body ng-app="clip" ng-controller="Main">
<h1> ngClip Example </h1>

<button type="button" clip-copy="getTextToCopy()" clip-click="doSomething()">Copy</button>
</body>
</html>

The above code is running on tomcat.

查看更多
登录 后发表回答