I'm using jQueryUI in combination with RequireJS and AngularJS. I wrapped the jqueryui components in require statements like:
define(['jquery','./core','./mouse', './widget'], function (jQuery) {
(function( $, undefined ) {
$.widget("ui.draggable", $.ui.mouse, {....});
})(jQuery);
});
and created a AngularJS directive to wrap it like:
require(['angular', 'app', 'jquery', 'lib/jquery-ui/draggable'], function(angular, app, $){
app.directive('draggable', ['$timeout','draggableConfig', function ($timeout) {
return {
restrict: 'AE',
scope: {
ngModel: '=',
options: '='
},
link: function ($scope, $element, $attributes) {
$timeout(function(){
$element.draggable();
}, 50)
}
}
}]);
});
but 2 out of every 5 times the app throws an error like:
TypeError: Object [object Object] has no method 'draggable'
at http://localhost/phoenix/directives/draggable.js:21:30
at http://localhost/phoenix/lib/angular/angular.js:13152:28
at completeOutstandingRequest (http://localhost/phoenix/lib/angular/angular.js:3996:10)
at http://localhost/phoenix/lib/angular/angular.js:4302:7
I've tried countless things but had no luck consistently. I'm pretty sure the draggable isn't getting bound to the $ by load time of the directive but the dependencies are right so I'm lost why. Any thoughts?