简体   繁体   English

如何在 uib-datepicker 中设置 maxdate 和 mindate

[英]How to set maxdate and mindate in uib-datepicker

Below is my Controller and html code where I'm implementing date and can someone explain me how to add maxdate and mindate to below code.下面是我的控制器和 html 代码,我在其中实现了日期,有人可以向我解释如何将 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>

You can use maxDate and minDate in datepicker options.您可以在日期选择器选项中使用maxDateminDate

According to documentation根据文档

to configure the uib-datepicker you need to create an object in Javascript with all the options and use it on the datepicker-options attribute要配置 uib-datepicker,您需要在 Javascript 中创建一个包含所有选项的对象,并在 datepicker-options 属性上使用它

so in your html所以在你的 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" />

and in your controller并在您的控制器中

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

Have a look at this plunker看看这个plunker

In AngularJS you can set a series of dateOptions such as dateMin, dateMax for the uib-datepickerAngularJS你可以为uib-datepicker datepicker 设置一系列的 dateOptions 比如 dateMin, dateMax

Check this plunker taken from this thread检查从这个线程中获取的这个plunker

You can do it with tag it self你可以用标签自己来做到这一点

In controller在控制器中

$scope.minDate = new Date();

In view在视图中

 min-date="minDate" // add in uib-input

Just tested and Works fine刚刚测试并且工作正常

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM