I am trying to get an AngularJS directive that uses jQuery-UI to work in jsfiddle.
- jQuery-UI works fine when used directly
- AngularJS works
- but the directive reports: "element.datepicker is not a function"
What do I need to do to get jQuery-UI to work inside the directive in jsFiddle?
http://jsfiddle.net/edwardtanguay/oqo2xv3e/1
HTML
<div ng-app="mainApp">
<div ng-controller="mainController">
<div>{{message}}</div>
<input id="normal" type="text" />
<input id="startDate" type="text" ng-model="date" jqdatepicker />
</div>
</div>
JavaScript
angular.module('mainApp', [])
.controller('mainController', function($scope) {
$scope.message = 'test111';
$('#normal').datepicker();
})
.directive('jqdatepicker', function () {
return {
restrict: 'A',
require: 'ngModel',
link: function (scope, element, attrs, ngModelCtrl) {
element.datepicker({
dateFormat: 'DD, d MM, yy',
onSelect: function (date) {
scope.date = date;
scope.$apply();
}
});
}
};
});