加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

angularjs – Angular Bootstrap datepicker自定义类

发布时间:2020-12-17 06:48:00 所属栏目:安全 来源:网络整理
导读:我正在使用Angular和UI Bootstrap Datepicker( https://angular-ui.github.io/bootstrap/),我正在尝试更新日期类,以显示使用现有customClass在特定日期发生的事情.当传递的日期是同步但使用$resource不是异步时,这可以正常工作. HTML uib-datepicker custom-
我正在使用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):

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

解决方法

我有同样的问题,要修复它我在包含uib-datepicker的元素中放了一个ng-if =“variable”.

“variable”应该是myCalendarEvents,当显示uib-datepicker时,数据可用

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读