我想在angularJS中禁用日期(星期一到星期日)和特定日期。目前我正在使用UI Bootstrap DateTimePicker。一切正常,但是当我从API中获取数据时,数据无法正常工作,或者API会执行大量调用以便工作。
<datetimepicker ng-change="dateChanged(date, mode)"
ng-model="date" hidden-time="true" hidden-date="false"
disabled-date="false" show-button-bar="false"
date-options="dateOptions" date-format="EEE, MMM d, y"
date-disabled="isDisabledDate(date, mode)"></datetimepicker>
控制器
$scope.isDisabledDate = function(currentDate, mode) {
// This will disable Every Monday & Tuesday and the specific date.
// 0: Monday, 1: Tuesday ... 6: Sunday
return mode === 'day' && (currentDate.getDay() == 0 || currentDate.getDay() == 1)
|| ($filter('date')(new Date(currentDate),"yyyy-MM-dd") == "2017-05-15");
}
API禁用日
"delivery_day": {
"monday": 0,
"tuesday": 0,
"wednesday": 1,
"thursday": 1,
"friday": 1,
"saturday": 1,
"sunday": 1
}
它显示每周一和周二都是休息日
API禁用日期
"disabled_dates": [
"2017-07-11"
]
问题
当页面启动时,isDisabledDate函数将被多次调用。我不知道如何解析&#34; API禁用日&#34;进入该函数,不要让API调用多次。
Checkout Plunker:https://plnkr.co/edit/Aow7CXFvQUYiMICUgU9T