无法在Angular js中设置minDate和MaxDate datepicker

时间:2017-09-11 12:27:27

标签: javascript jquery angularjs datepicker

我是角度JS的新手,我正在尝试修复minDatemaxDate以及最新的选择器,我已尝试过下面的代码,但它无效:

<input type="text" name="mydate" id="sd" min-date="minDate" placeholder="Select a date" class="form-control datepicker" min-date="minDate" ng-model="enquiry.startdate" ng-blur="updateRate()" required>
    <span class="input-group-addon">
        <i class="fa fa-calendar"></i>
    </span>

以下是我的控制器代码:

function enquiryCtrl($scope,DataServices,$stateParams,SweetAlert,$state,DTOptionsBuilder,DTColumnDefBuilder){
    // some other code
    var date = new Date();
    $scope.minDate=date; //I am trying to set today date as minDate
}

但它没有工作它也过去的日期

以下是已编辑的代码

function getMinDate()
{
    console.log("From Date---- "+$('#sd').text())
    return $('#sd').val();
}

$('#dd').daterangepicker({
    "singleDatePicker": true,
    "dateLimit": {
        "days": 7
    },


    "minDate":getMinDate(),

},function(start, end, label) {
      console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});

$('#sd').daterangepicker({
    "singleDatePicker": true,
    "dateLimit": {
        "days": 7
    },
    "startDate": new Date(),
    "endDate": new Date(),
    "minDate": new Date()
},function(start, end, label) {
      console.log("New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')");
});

1 个答案:

答案 0 :(得分:0)

<div class="demo">
<p>Date: <input type="text" id="datepicker" /></p>

  

$(function(){       $(“#datepicker”)。datepicker({           dateFormat:“dd / mm / yy”,           changeYear:true,           changeYear:true,           minDate:new Date(),           maxDate:新日期(2017年,10-1,30)       });   });