【发布时间】:2019-10-29 06:04:48
【问题描述】:
我使用 Angular ui.bootstrap datepicker 我需要根据我选择的其他日期动态设置最小日期。 贝娄我添加了我尝试过的代码。我将首先选择“到”日期。根据选择的“到”日期,我需要为“从”日期设置最小日期。 'From' date min 应该是 'To' Date 中选择的日期之前的 30 天。
JS.
$scope.showButtonBar = false;
$scope.disabled = true;
$scope.today = function() {
$scope.dt;
};
$scope.dtmax = new Date();
$scope.dateformat = "dd/MM/yyyy";
$scope.today();
$scope.showto = function($event) {
$scope.showdpto = true;
};
$scope.showfrom = function($event) {
$scope.showdpfrom = true;
};
$scope.setFrom = function(){
$scope.disabled = false;
$scope.dfmax = $scope.dt;
$scope.dfMin = $scope.dt-30; // this is not working
//$scope.dfMin = ($scope.dt.getDate() - 30); //this is also not working
$scope.df = "";
$scope.$apply();
}
$scope.Search = function(){
console.log($scope.dt);
console.log($scope.df);
console.log($scope.dfMax);
}
HTML
From:
<input type="text" uib-datepicker-popup="{{dateformat}}" showWeeks="false"
show-button-bar="false" ng-model="df" is-open="showdpfrom"
max-date="dfmax" min-date="dfMin"
ng-style="disabled ? {'background-color':'#000'}:{'background-color':'fff'}"/>
<span>
<button type="button" ng-disabled="disabled" class="btn btn-default"
ng-click="showfrom($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
</span>
TO:
<input type="text" uib-datepicker-popup="{{dateformat}}" showWeeks="false"
show-button-bar="false"
ng-model="dt" is-open="showdpto" max-date="dtmax"
ng-change="setFrom()"/>
<span>
<button type="button" class="btn btn-default" ng-click="showto($event)">
<i class="glyphicon glyphicon-calendar"></i>
</button>
<button class="btn-confirm" ng-click="Search()">SEARCH</button>
</span>
【问题讨论】:
标签: javascript angularjs angular-ui-bootstrap