-1
モードがdayの場合、Datepickerから表示可能な日付を取得する必要があります。angle bootstrap datepickerは表示される日付を取得します(日モード)
例:私はこれらの42日取得する必要があります。この場合
。また、ユーザーが月を変更した場合は、Datepickerのコントローラービューを更新して42日を新たに取得する必要があります。
モードがdayの場合、Datepickerから表示可能な日付を取得する必要があります。angle bootstrap datepickerは表示される日付を取得します(日モード)
例:私はこれらの42日取得する必要があります。この場合
。また、ユーザーが月を変更した場合は、Datepickerのコントローラービューを更新して42日を新たに取得する必要があります。
私はこれを修正することができました。 我々はuibDatepickerDirective
angular.module('ui.bootstrap.datepicker')
.config(function ($provide) {
$provide.decorator('uibDatepickerDirective', function ($delegate, $timeout) {
var directive = $delegate[0];
var link = directive.link;
angular.extend(directive.scope, {
visibleDates: '=?'
});
directive.compile = function() {
return function (scope, element, attrs, ctrls) {
link.apply(this, arguments);
var datepickerCtrl = ctrls[0];
datepickerCtrl.getVisibleDates = function() {
var year = this.activeDate.getFullYear(),
month = this.activeDate.getMonth(),
firstDayOfMonth = new Date(this.activeDate);
firstDayOfMonth.setFullYear(year, month, 1);
var difference = this.startingDay - firstDayOfMonth.getDay(),
numDisplayedFromPreviousMonth = difference > 0 ?
7 - difference : -difference,
firstDate = new Date(firstDayOfMonth);
if (numDisplayedFromPreviousMonth > 0) {
firstDate.setDate(-numDisplayedFromPreviousMonth + 1);
}
return this.getDates(firstDate, 42);;
}
var firstTime = true;
$timeout(function() {
scope.$watch("activeDt", function() {
var newValues = datepickerCtrl.getVisibleDates();
if (firstTime) {
scope.visibleDates = newValues;
firstTime = false;
return;
}
if (newValues[0].getYear() !== scope.visibleDates[0].getYear() ||
newValues[0].getMonth() !== scope.visibleDates[0].getMonth() ||
newValues[0].getDate() !== scope.visibleDates[0].getDate()) {
scope.visibleDates = newValues;
}
});
});
}
};
return $delegate;
});
});
を拡張する必要があり、ディレクティブ自体に、我々はこれらの42日間保存したい変数にatribute可視日付とポイントを渡す必要があります。
<span uib-datepicker visible-dates="visibleDates" datepicker- ng-model="datePicked"></span>
我々は日付ピッカーで月を変更した場合、我々はvisibleDates(それらの42)が更新されますが、私たちは同じ月(同じ目に見える日付)にactiveDate(scope.activeDt)を変更した場合、それは変わらないままになりますこの方法です。