回答

1

完成它。

使用beforeRender功能,並禁用未來的日期與當前的日期進行比較的utcDateValue

下面是代碼:

$scope.beforeRender = function ($dates) { 
    /* disable future dates */ 
    for(var i=0; i<$dates.length;i++) { 
     if(new Date().getTime() < $dates[i].utcDateValue) { 
      $dates[i].selectable = false; 
     } 
    }     
}; 

新增data-before-render="beforeRender($dates)"以及我需要完全相反的要求,即稍微複雜一些,只允許未來

<datetimepicker data-ng-model="user.join_date" data-datetimepicker-config="{ startView:'day', minView:'day' }" data-before-render="beforeRender($dates)" /> 
0

只允許未來

日期您需要考慮參數$ view

Javascript:

$scope.futureOnlyBeforeRender = function($view, $dates) { 
// $view values: year, month, day, hour, minute 
var currentDate = new Date(); 
// set the current date according to the view 
switch($view){ 
    case 'year': currentDate.setYear(currentDate.getYear() - 1); break; 
    case 'month': currentDate.setMonth(currentDate.getMonth() - 1); break; 
    case 'day': currentDate.setDate(currentDate.getDate() - 1); break; 
    case 'hour': currentDate.setHours(currentDate.getHours() - 1); break; 
    case 'minute': currentDate.setMinutes(currentDate.getMinutes() - 1); break; 
} 
// apply ot the dates 
$dates.filter(function (date) { 
    return date.utcDateValue < currentDate.getTime(); 
}).forEach(function (date) { 
    date.selectable = false; 
}) 

};;

HTML:

data-before-render="futureOnlyBeforeRender($view, $dates)" 
相關問題