0

I want to use this tinyColorPicker plugin https://github.com/PitPik/tinyColorPicker but it's proving extremely difficult to use it in my angular app.

I keep getting this error:

TypeError: element.colorPicker is not a function

In my index.html

<script src="bower_components/jquery/dist/jquery.js"></script>
<script src="bower_components/tinycolorpicker/lib/jquery.tinycolorpicker.js"></script>

I have then made a directive to instantiate the plugin

'use strict';
angular.module('myApp')
  .directive('colorWheel', function() {
      return {
          restrict: 'A',
          link: function(scope, element) {
              element.colorPicker();
          }
      };
  });

And in my HTML I have this div with the directive

<div id="colorWheel" color-wheel></div>

According to their docs that is all I have to do. I must be missing something key when it comes to integrating it with Angular. Can anyone see anything? Thanks

2
  • I think you have to load jQuery to make it work. Did you load it? Commented Nov 26, 2015 at 20:23
  • Yes! sorry, I have jquery at the top loaded... ill update it Commented Nov 26, 2015 at 20:27

2 Answers 2

2

Element is not a jQuery object, it is an angular object. The plugin is is exposed on the jQuery object. Try using jQuery selectors in your link fn e.g. jQuery("#yourDomId").colorPicker()

Sign up to request clarification or add additional context in comments.

Comments

1

You have to load jQuery before you loading angularjs.

If you will load jquery after loading angular you will get the jqLite.

<script src="jquery.js"></script>
<sciprt src="angular.js"></script>

1 Comment

@tester123 you have loaded it but you are not using it in your link function - you are trying to initialise colorPicker on element - do it on a jquery object instead... $('#myId').colorPicker();

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.