5

I'm using Angular with UI Bootstrap Datepicker (https://angular-ui.github.io/bootstrap/) and I'm trying to update the day class to show there is something happening on that specific day using the existing customClass. This works fine when the dates passed are sync but not async using a $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, 0, 0);

            for (var i = 0; i < $scope.myCalendarEvents.length; i++) {

            var currentDay = new Date($scope.myCalendarEvents[i].startDate).setHours(0, 0, 0, 0);

            if (dayToCheck === currentDay) {

                return "full";

            }
        }

    }

    return '';
}               

};

See example where the async call is made (ps. this is not my Plnkr):

http://plnkr.co/edit/h8PxWfxSEtZuVCct00mD?p=preview

1 Answer 1

4

I had the same problem, to fix it I put an ng-if="variable" in element which contains the uib-datepicker.

"variable" should be myCalendarEvents, and when the uib-datepicker is displayed the data is available

Sign up to request clarification or add additional context in comments.

1 Comment

Could you post your code showing this in context? I am having the same issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.