sachinchoolur/ngclipboard

Clipboard is not a constructor

dfa1234 opened this issue · 13 comments

Please provide a jsfiddle demo for your setup..

Remember to include the Clipboard.js file first.

I am getting this same error as well. Has there been a fix or a find for the issue?

Let me guess : you did not included the clipboard.js file as I mentioned right above.

<script src="dist/clipboard.min.js"></script>
<script src="dist/ngclipboard.min.js"></script>

thanks. sorry, I am super new to angular.

I am getting this same error as well. Has there been a fix or a find for the issue?:)
I'm including "clipboard.js" before "ngclipboard" with requirejs, but have error "Clipboard is not a constructor". I user "clipboard.js v1.5.10" and "ngclipboard - v1.1.1".

Having same error.

I dont want to load clipboard via script tag as mentioned on the README, I am using requireJS to load ngclipboard and clipboard. I have also defined clipboard as dependency of ngclipboard so that requireJS will load clipboard before loading ngclipboard.

But it just doesnt work, Same error stack as above.

in ngclipboard.js, it loads sets the angular from window.angular.. but window.Clipboard is always undefined.

+1.
I guess I'm hopping on the requireJS-problem wagon.

che85 commented

I am having the same issue when loading via requirejs

che85 commented

As a workaround I did the following in my main.js

require.config({
  paths: {
    "angular": "../bower_components/angular/angular",
    "jquery": "../bower_components/jquery/dist/jquery.min",
    "clipboard": "../bower_components/clipboard/dist/clipboard.min",
    "ngclipboard": "../bower_components/ngclipboard/dist/ngclipboard.min",
    "app": "app"
  },
  shim: {
    "angular": {
      deps: ["jquery"]
    },
    "app": {
      deps: ["angular", "ngclipboard"]
    },
    "ngclipboard": {
      deps: ["angular", "clipboard"]
    }
  }
});

require(['clipboard'], function(clipboard) {
  window.Clipboard = clipboard;
});

require(["app"],
  function () {
    angular.bootstrap(document, ["app"]);
  }
);

The most important part obviously is:

require(['clipboard'], function(clipboard) {
  window.Clipboard = clipboard;
});

This works fine for me.

To add to @che85 answer.
I had to assign Window.ClipboardJS = clipboard;. Also, it was important to do

require(['clipboard'], function(clipboard) {
	window.ClipboardJS = clipboard;
});

before, and separately from, bootstrapping the app.

angular.js:14199 TypeError: ClipboardJS is not a constructor
at Object.link (:28:33)
at http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:16:71
at http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:82:187
at sa (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:82:244)
at n (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:68:6)
at g (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:59:428)
at g (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:59:445)
at g (http://scdevapp13.corp.amdocs.com:8000/widget/app/******/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:59:445)
at n (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:67:452)
at g (http://scdevapp13.corp.amdocs.com:8000/widget/app/*****/components/uniprovision/template/bower_components/angular/angular.min.js?ossVersion=202002111807:59:428)

I am using angular v1.5.11, does it matter?