{"id":1765,"date":"2022-08-30T15:19:15","date_gmt":"2022-08-30T15:19:15","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2013\/12\/02\/how-to-use-jquery-plugins-in-angularjs-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:19:15","modified_gmt":"2022-08-30T15:19:15","slug":"how-to-use-jquery-plugins-in-angularjs-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/how-to-use-jquery-plugins-in-angularjs-collection-of-common-programming-errors\/","title":{"rendered":"How to use jQuery plugins in AngularJS?-Collection of common programming errors"},"content":{"rendered":"<p>I am using AngularJS 1.2 and trying to include a jQuery plugin via an Angular Directive. As an example I have chosen a plugin called spectrum. I have not included (and do not wish to include) jQuery separately, as AngularJS is said to include jqLite, a smaller version of jQuery.<\/p>\n<pre><code>myDirs.directive('spectrumDir', function() {\n    return {\n        restrict: 'A',\n        link: function(scope, element, attrs) {\n            angular.element(element).spectrum(scope.$eval(attrs.spectrumDir));\n        }\n    };\n});\n<\/code><\/pre>\n<p>However, when i try to load the app, I get:<\/p>\n<blockquote>\n<p>Uncaught ReferenceError: jQuery is not defined spectrum.js:1888 (anonymous function)<\/p>\n<\/blockquote>\n<p>The error stems from the initialization of the plugin:<\/p>\n<pre><code>(function (window, $, undefined) {\n    .code.\n})(window, jQuery);\n<\/code><\/pre>\n<p>What is the generic solution to including jQuery plugins in AngularJS? Is there any elegant way to achieve this without including the full jQuery library?<\/p>\n<blockquote>\n<p>AngularJS comes bundled with a lite implementation of jQuery referred to as jqLite. For Angular&#8217;s purposes, this is effectively jQuery, albeit an extremely gutted one. The creators of Angular believe the jqLite API to be sufficient for nearly every application if utilized properly.<\/p>\n<\/blockquote>\n<ol>\n<li>\n<p>As &#8220;Arun P Johny&#8221; said, you must FIRST include the jquery javascript and then your plugin which depends on jQuery<\/p>\n<\/li>\n<\/ol>\n<p id=\"rop\"><small>Originally posted 2013-12-02 01:20:27. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>I am using AngularJS 1.2 and trying to include a jQuery plugin via an Angular Directive. As an example I have chosen a plugin called spectrum. I have not included (and do not wish to include) jQuery separately, as AngularJS is said to include jqLite, a smaller version of jQuery. myDirs.directive(&#8216;spectrumDir&#8217;, function() { return { [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-1765","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1765","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=1765"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/1765\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=1765"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=1765"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=1765"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}