我无法在自定义设置日找到任何内容。默认情况下,它始终选择当前年份的当前日期。如何设置不同的日期和年份。
HTML
<div>
<multiple-date-picker></multiple-date-picker>
</div>
我看到了datepicker的整个文件。我刚刚看到这些与今天有关的行。
var checkNavigationButtons = function () {
var today = moment(),
previousMonth = moment(scope.month).subtract(1, 'month'),
nextMonth = moment(scope.month).add(1, 'month');
scope.disableBackButton = scope.disallowBackPastMonths && today.isAfter(previousMonth, 'month');
scope.disableNextButton = scope.disallowGoFuturMonths && today.isBefore(nextMonth, 'month');
},
答案 0 :(得分:1)
谢谢@shashank提出这个想法。我解决了这个问题。
link: function (scope) {
/* if yes then find the last element of the dates array which
* is the last selected date of the year
* after that convert it into yyy-mm-dd format
* and assign to variable
*/
if(scope.lastdateOfSelectedyear[scope.lastdateOfSelectedyear.length - 1])
{
var lastDayOfYear = moment(scope.lastdateOfSelectedyear[scope.lastdateOfSelectedyear.length - 1].endValue).format('YYYY-MM-DD');
var objectTocontainSplittedString = {};
/* split the string and put it in seperate variable */
objectTocontainSplittedString = lastDayOfYear.split('-');
var month_of_date_selected = objectTocontainSplittedString[1];
var year_of_date_selected = objectTocontainSplittedString[0];
var day_of_date_selected = objectTocontainSplittedString[2];
/* last date of the selected dates month */
scope.month = moment(year_of_date_selected+'-
'+month_of_date_selected+'-'+day_of_date_selected);
}
}
其中lastdateOfSelectedyear
是我在指令调用中传递的数组,它包含用户选择的所有日期。
答案 1 :(得分:0)
正如官方文件中所述:
<multiple-date-picker ng-model="myArrayOfDates"></multiple-date-picker>
您可以尝试提供ng-model="selectedDate"
并将selectedDate
设置为:
HTML代码:
<multiple-date-picker ng-model="selectedDate"></multiple-date-picker>
JS代码:
$scope.selectedDate = moment().date(15); /* OUTPUT: 2018-03-15 */
/* -- or -- */
$scope.selectedDate = moment().date(2).month(10); /* OUTPUT: 2018-10-02 */
/* -- or -- */
$scope.selectedDate = moment().date(27).year(2017); /* OUTPUT: 2017-03-27 */