【发布时间】:2016-09-30 13:01:55
【问题描述】:
我需要设置“从”和“到”日期。我只想从明天或将来的任何日期开始设置“从”,而不是在过去。并在选择开始日期后,启用“到”选择器并设置结束日期,但最小日期范围。并在 dom 中显示日期范围。 我从官方页面尝试github解决方案,但一切都来自引导日期范围而不是角度日期范围。谢谢 这是html代码
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p class="input-group">
<input type="text"
class="form-control"
datetime-picker="yyyy-MM-dd"
ng-model="ctrl.picker4.date"
is-open="ctrl.picker4.open"
enable-time="false"
datepicker-options="ctrl.picker4.datepickerOptions"
myformat
/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="ctrl.openCalendar($event, 'picker4')"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
<div class="col-lg-5 col-md-5 col-sm-5 col-xs-12 form-group">
<label class="col-lg-2 col-xs-2 control-label" style="color: #fff">To</label>
<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
<p class="input-group">
<input type="text"
class="form-control"
datetime-picker="yyyy-MM-dd"
ng-model="ctrl.picker5.date"
is-open="ctrl.picker5.open"
enable-time="false"
datepicker-options="ctrl.picker5.datepickerOptions"
myformat
/>
<span class="input-group-btn">
<button type="button" class="btn btn-default" ng-click="ctrl.openCalendar($event, 'picker5')"><i class="glyphicon glyphicon-calendar"></i></button>
</span>
</p>
</div>
</div>
这里是控制器
//date picker
var that = this;
// date picker
// min date picker
this.picker4 = {
date: new Date(),
datepickerOptions: {
showWeeks: true,
startingDay: 1,
maxDate: null
}
};
// max date picker
this.picker5 = {
date: new Date(),
datepickerOptions: {
showWeeks: true,
startingDay: 1,
minDate: null
}
};
/*
// set date for max picker, 10 days in future
this.picker5.date.setDate(this.picker5.date.getDate() + 10);
*/
// when closed picker
this.picker13 = {
date: new Date(),
closed: function (args) {
that.closedArgs = args;
}
};
this.openCalendar = function (e, picker) {
that[picker].open = true;
};
// watch min and max dates to calculate difference
var unwatchMinMaxValues = $scope.$watch(function () {
return [that.picker4, that.picker5, that.picker10, that.picker11];
}, function () {
// min max dates
that.picker4.datepickerOptions.maxDate = that.picker5.date;
that.picker5.datepickerOptions.minDate = that.picker4.date;
if (that.picker4.date && that.picker5.date) {
var diff = that.picker4.date - that.picker5.date;
that.dayRange = Math.round(Math.abs(diff / (1000 * 60 * 60 * 24)))
} else {
that.dayRange = 'n/a';
}
}, true);
// destroy watcher
$scope.$on('$destroy', function () {
unwatchMinMaxValues();
});
【问题讨论】:
-
-
嗨,但我需要为明天设置日期。总有一天+