在angularjs中集成jquery插件

时间:2014-05-29 20:16:51

标签: jquery angularjs jquery-plugins angularjs-directive

我是Angular的新手,我对如何使用带有Angular的jquery插件感到有点困惑。

我想在我的角应用中使用subway map pluging

我为地铁地图创建了一个新指令:

angular.module('myApp.directives', []).
    directive('subwayMap', function() {
return {
    // Restrict it to be an attribute in this case
    restrict: 'A',
    // responsible for registering DOM listeners as well as updating the DOM
    link: function(scope, element, attrs) {


        angular.element(element).subwayMap({ debug: true });

    }
};

});

并在我的html页面中使用它:`

<div subway-Map>
    <ul data-color="#EF0010" data-label="jQuery Interactions" data-shiftCoords="0,-1">

       <li data-coords="20,14">O</li>
       <li data-coords="21,14">P</li>
       <li data-coords="22,14">Q</li>
       <li data-coords="23,14">R</li>
       <li data-coords="24,14">S</li>
    </ul>
</div>

但我在subwaymap js中有错误:

ReferenceError: jQuery is not defined

})(jQuery的);

如何解决这个错误?

感谢您的帮助

编辑:

问题出在指令文件中,这是我的指令文件,当我删除subwayMap时appVersion指令工作

感谢      /*global define / 'use strict'; define(['angular'], function(angular) { / Directives */ angular.module('myApp.directives', []). directive('appVersion', ['version', function(version) { return function(scope, elm, attrs) { elm.text(version); }; }]); angular.module('myApp.directives', []). directive('subwayMap', function() { return { // Restrict it to be an attribute in this case restrict: 'A', // responsible for registering DOM listeners as well as updating the DOM link: function(scope, element, attrs) { angular.element(element).subwayMap({ debug: true }); } }; }); }); thnks

0 个答案:

没有答案