我正在使用Angular和UI Bootstrap Datepicker(
https://angular-ui.github.io/bootstrap/),我正在尝试更新日期类,以显示使用现有customClass在特定日期发生的事情.当传递的日期是同步但使用$resource不是异步时,这可以正常工作.
HTML
<uib-datepicker custom-class="getDayClass(date,mode)" ng-model="dt" min-date="minDate" show-weeks="false" starting-day="1" class="well well-sm" ng-change="selectDateChange()"></uib-datepicker>
JS
$scope.getDayClass = function (date,mode) { if ($scope.myCalendarEvents.length > 0) { if (mode === 'day') { var daytocheck = new Date(date).setHours(0,0); for (var i = 0; i < $scope.myCalendarEvents.length; i++) { var currentDay = new Date($scope.myCalendarEvents[i].startDate).setHours(0,0); if (daytocheck === currentDay) { return "full"; } } } return ''; } };
查看异步调用的示例(ps.这不是我的Plnkr):
解决方法
我有同样的问题,要修复它我在包含uib-datepicker的元素中放了一个ng-if =“variable”.
“variable”应该是myCalendarEvents,当显示uib-datepicker时,数据可用