【发布时间】:2016-03-09 19:20:07
【问题描述】:
我正在为 jQuery UI datepicker 编写一个 AngularJS 指令。我想在滚动时隐藏下拉日历,但现在我无法隐藏它。你可以访问我的 plunker 来查看它。 https://plnkr.co/edit/CuJB1vsKuaqfkh8NFUXb?p=preview
我的指令如下:
module.directive('myDatePicker', ['$window', '$timeout',
function($window, $timeout) {
return {
restrict: 'A',
require: "ngModel",
link: linkFunc
};
}
]);
function linkFunc(scope, element, attr, ngModelCtrl) {
var updateModel = function(dateText) {
scope.$apply(function() {
ngModelCtrl.$setViewValue(dateText);
});
};
var options = {
onSelect: function(dateText) {
updateModel(dateText);
},
hideOnInputClick: true,
maxDate: "+0d",
selectOtherMonths: true
};
element.datepicker(options);
var body = element.find('body');
body.bind('scroll', function() {
element.find('#ui-datepicker-div').hide();
scope.apply();
});
}
有谁知道为什么会发生这种情况以及如何隐藏日历?
【问题讨论】:
标签: jquery angularjs jquery-ui angularjs-directive jquery-ui-datepicker