angular-ui datepicker max-date无法正常工作 [英] angular-ui datepicker max-date doesn't work properly

查看:160
本文介绍了angular-ui datepicker max-date无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从<$ c中设置最小日期 max-date $ c> datepicker-options ,但未成功。附上一个代码片段。



任何帮助?谢谢!



< pre class =snippet-code-js lang-js prettyprint-override> angular.module('ui.bootstrap.demo',['ui.bootstrap']); angular.module('ui .bootstrap.demo')。controller('DatepickerDemoCtrl',function($ scope){$ scope.today = function(){$ scope.dt = new Date();}; $ scope.today(); $ scope。 dateOptions = {formatYear:'yy',minDate:'05 / 01/2015',startingDay:1}; $ scope.formats = ['dd / MM / yyyy','dd-MMMM-yyyy','yyyy / MM / dd','dd.MM.yyyy','shortDate']; $ scope.format = $ scope.formats [0]; var tomorrow = new Date(); tomorrow.setDate(tomorrow.getDate()+ 1) ; var afterTomorrow = new Date(); afterTomorrow.setDate(tomorrow.getDate()+ 2); $ scope.events = [{date:tomorrow,status:'full'},{date:afterTomorrow,status:'partial' }]; $ scope.getDayClass = function (date,mode){if(mode ==='day'){var dayToCheck = new Date(date).setHours(0,0,0,0); for(var i = 0; i< $ scope.events.length; i ++){var currentDay = new Date($ scope.events [i] .date).setHours(0,0,0,0); if(dayToCheck === currentDay){return $ scope.events [i] .status; }}} return''; };});

 <!doctype html>< ; html ng-app =ui.bootstrap.demo> < head> < script src =// ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js\"></script> < script src =// angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js\"></script> < link href =// netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css =stylesheet> < / head> < body>< style>丰富的按钮跨度{background-color:limegreen; border-radius:32px;颜色:黑色} .partially button span {background-color:orange; border-radius:32px;颜色:黑色}< / style>< divng-controller =DatepickerDemoCtrl> < pre>选定的日期是:< em> {{dt | date:'fullDate'}}< / em>< / pre> < h4> Inline< / h4> < div style =display:inline-block; min-height:290px;> < datepicker ng-model =dtdatepicker-options =dateOptionsclass =well well-smcustom-class =getDayClass(date,mode)>< / datepicker> < / div>< / div> < / body>< / html>  

解决方案

< datepicker ng-model =dtminDate ='05/01/2015'datepicker-options =dateOptionsclass =well well-smcustom -class =getDayClass(date,mode)>< / datepicker> 尝试这个,把minDate放在标记中


I am trying to get the min-date and max-date to be set from the datepicker-options, but have been unsuccessful. A code snippet is attached.

Any help? Thanks!

angular.module('ui.bootstrap.demo', ['ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('DatepickerDemoCtrl', function ($scope) {
  $scope.today = function() {
    $scope.dt = new Date();
  };
  $scope.today();

  $scope.dateOptions = {
    formatYear: 'yy',
    minDate: '05/01/2015',
    startingDay: 1
  };

  $scope.formats =['dd/MM/yyyy', 'dd-MMMM-yyyy', 'yyyy/MM/dd', 'dd.MM.yyyy', 'shortDate'];
  $scope.format = $scope.formats[0];

  var tomorrow = new Date();
  tomorrow.setDate(tomorrow.getDate() + 1);
  var afterTomorrow = new Date();
  afterTomorrow.setDate(tomorrow.getDate() + 2);
  $scope.events =
    [
      {
        date: tomorrow,
        status: 'full'
      },
      {
        date: afterTomorrow,
        status: 'partially'
      }
    ];

  $scope.getDayClass = function(date, mode) {
    if (mode === 'day') {
      var dayToCheck = new Date(date).setHours(0,0,0,0);

      for (var i=0;i<$scope.events.length;i++){
        var currentDay = new Date($scope.events[i].date).setHours(0,0,0,0);

        if (dayToCheck === currentDay) {
          return $scope.events[i].status;
        }
      }
    }

    return '';
  };
});

<!doctype html>
<html ng-app="ui.bootstrap.demo">
  <head>
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.13/angular.js"></script>
    <script src="//angular-ui.github.io/bootstrap/ui-bootstrap-tpls-0.13.0.js"></script>
    <link href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css" rel="stylesheet">
  </head>
  <body>

<style>
  .full button span {
    background-color: limegreen;
    border-radius: 32px;
    color: black;
  }
  .partially button span {
    background-color: orange;
    border-radius: 32px;
    color: black;
  }
</style>
<div ng-controller="DatepickerDemoCtrl">
    <pre>Selected date is: <em>{{dt | date:'fullDate' }}</em></pre>

    <h4>Inline</h4>
    <div style="display:inline-block; min-height:290px;">
      <datepicker ng-model="dt" datepicker-options="dateOptions" class="well well-sm" custom-class="getDayClass(date, mode)"></datepicker>
    </div>
</div>
  </body>
</html>

解决方案

<datepicker ng-model="dt" minDate="'05/01/2015'" datepicker-options="dateOptions" class="well well-sm" custom-class="getDayClass(date, mode)"></datepicker> try this, put the minDate in the markup

这篇关于angular-ui datepicker max-date无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆