我試圖在其範圍更改時讓我的datePicker更新。我已經添加了手錶,但這似乎阻止了customClass函數的發射。
指令HTML
<datepicker-calendar search-response="searchResponse"></datepicker-calendar>
指令模板(日期選擇器)
<div uib-datepicker ng-model="dt" class="well well-sm" datepicker-options="options" ng-if="dt"></div>
角指令代碼
var datepickerCalendarDirective = function datepickerCalendarDirective() {
return {
scope: {
searchResponse: '='
},
restrict: 'E',
templateUrl: './templates/directive.datepickerCalendar.tmpl.html',
link: function link(scope, element, attrs, $filter, policySessionService) {
scope.$watch('searchResponse', function() {
scope.dt = new Date();
if (!scope.searchResponse) return '';
/* setup the date picker options object.
* this takes a customClass function which sets the
* css class of the trips/events on the datepicker
*/
scope.options = {
customClass: getSelectedDates,
maxDate: new Date(),
showWeeks: false,
startingDay: 1 };
}, true);
/* Iterate over each trip in the reponse and return either
* a trip or incident css class to the customClass param
* of the datepicker options object
*/
function getSelectedDates(data) {
if (scope.searchResponse.data[0] && data.mode === 'day') {
var trips = $filter('orderBy')(scope.searchResponse.data[0].tripDates, 'JourneyDate'),
journeyDate;
for (var i = 0; i < trips.length; i++) {
journeyDate = new Date(trips[i].JourneyDate).setHours(0, 0, 0, 0);
if (journeyDate === new Date(data.date).setHours(0, 0, 0, 0)) {
// return the appropriate css class for the trip type (trip or incident)
if (trips[i].IncidentRecorded) {
return 'incident';
} else {
return 'trip';
}
}
}
}
return '';
}
// });
}
};
};
如果我刪除的範圍看,然後一切按預期工作和customClass功能火災不是
您能否提供'。/ templates/directive.datepickerCalendar.tmpl.html'。此外,爲什麼你甚至需要reinit datepicker,你可以看模型,只是改變父級元素上的類 – Leguest
我已經添加了datepicker模板的請求 –