2017-02-15 32 views
0

下面是我的控制器和html代碼,我正在實施日期,並且有人可以向我解釋如何向下面的代碼添加maxdate和mindate。如何在uib-datepicker中設置maxdate和mindate

app.controller('viewfullproductionsummaryController', function ($scope, productionService, usSpinnerService) { 
 
    $scope.open1 = function() { $scope.popup1.opened = true; }; 
 
    $scope.popup1 = { opened: false }; 
 
    $scope.data = {}; 
 
    $scope.data.ProductionReportDate = new Date(); 
 
    });
<div class="col-md-2 inputGroupContainer"> 
 
    <div class="input-group"> 
 
     <span class="input-group-btn"> 
 
     <button type="button" class="btn btn-default" ng-click="open1()"><i class="glyphicon glyphicon-calendar"></i></button> 
 
     </span> 
 
     <input type="text" class="form-control" uib-datepicker-popup="dd-MMM-yyyy" ng-model="data.ProductionReportDate" is-open="popup1.opened" required close-text="Close" /> 
 
    </div> 
 
</div>

回答

1

可以在日期選擇器選項使用maxDateminDate

根據文檔

配置UIB,日期選擇器,你需要創建 的Javascript對象與所有的選擇和使用它的日期選擇器選項 屬性

所以在您的html

<input type="text" class="form-control" uib-datepicker-popup="dd-MMM-yyyy" ng-model="data.ProductionReportDate" is-open="popup1.opened" datepicker-options="options" required close-text="Close" /> 

並在您的控制器中

$scope.options = { 
     minDate: new Date(), // set this to whatever date you want to set 
    } 

看一看這個plunker

+0

我試圖採取的但他們不工作。你能告訴我用excat代碼如何實現? – Ranger

+0

我已經更新了我的答案,看看 –

+0

非常感謝Nishant。它爲我工作... :))) – Ranger

2

AngularJS您可以設置一系列dateOptions如dateMin,dateMax爲uib-datepicker

入住這plunker從這個thread

相關問題