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

标签 javascript angularjs html

下面是我的 Controller 和 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>

最佳答案

您可以在日期选择器选项中使用 maxDateminDate

根据文档

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

所以在你的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" />

在你的 Controller 中

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

看看这个 plunker

关于javascript - 如何在uib-datepicker中设置maxdate和mindate,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42259339/

相关文章:

javascript - 单击一下即可切换两个不同的 div

javascript - AngularJS 使用输入值属性

html - 屏幕变小时更改 Bootstrap 中的位置顺序

javascript - GridLayout ListView 的渲染非常慢 - WinJS

javascript - 如何将数据从新窗口传递到父窗口

javascript - Angular Controller 的属性在其功能之外不可访问

angularjs - 为什么大多数浏览器上的预检请求中不包含 TLS 客户端证书?

javascript - 悬停在图片上时显示说明

javascript - 使用 javascript 更改 html 文本并再次返回

javascript - jQuery - 将事件处理程序附加到预先存在的点击事件