【问题标题】:date-max-limit="" is not working in 720kb/angular-datepicker?date-max-limit="" 在 720kb/angular-datepicker 中不起作用?
【发布时间】:2018-02-14 12:41:15
【问题描述】:

我正在使用 720kb/angular-datepicker。 date-max-limit 不起作用。

我的控制器

$scope.currentDate = new Date().toString();

我的 HTML 库

<datepicker date-format="yyyy-MM-dd">
<input type='text' class="titleInput date" id="lastmodifiedDate" name="lastmodifiedDate"
       date-max-limit="{{currentDate}}"
       ng-model="studyDetails.lastmodifiedDate" ng-blur="updateStudy('isForceSave')"/>

Github 库链接here

【问题讨论】:

  • 确保添加您迄今为止尝试过的内容以及出错的内容。还尝试包括输出和/或错误,以便我们可以更好地帮助您。请记住,Stack Overflow 不是一个代码编写服务,但是如果你努力解释你的问题,这里有很多乐于助人的人。
  • 我已经添加了 github 库链接,根据“date-max-limit”应该可以工作,但它不会。我想在日期选择器中禁用未来日期

标签: javascript angularjs datepicker


【解决方案1】:

您传递了错误的日期格式。无需转换为日期格式。只需定义如下 & 在 date-max-limit 中以这种方式传递日期“{{maxDate | date}}”。您需要添加日期过滤器.它一定会起作用的。

$scope.maxDate = new Date();

<div class="datepicker w-80 pull-right"
                    date-format="dd-MMMM-yyyy"               
                    date-max-limit="{{maxDate | date}}"
                    button-prev='<i class="fa fa-arrow-circle-left"></i>'
                    button-next='<i class="fa fa-arrow-circle-right"></i>'>                                                      
                   <input placeholder="Select DOB" readonly ng-model="users.dob" type="text"  class="searchbar3 w-100"  />

【讨论】:

  • 请在答案中添加一些细节。
【解决方案2】:

您的日期不符合您输入的日期格式,因此请尝试替换:

$scope.currentDate = new Date().toString();

有了这个:

$scope.currentDate = new Date().toISOString().split('T')[0];

【讨论】:

  • 仍然无法正常工作。我尝试了这种不同的方式。 1> $scope.currentDate - 新日期().toDateString(); 2> $scope.currentDate = new Date().toISOString().split('T')[0]; 3> $scope.currentDate = $filter('date')(new Date(),'yyyy-MM-dd');
【解决方案3】:

您的 html 结构错误。将 date-max-limit="{{currentDate}}" 移动到 &lt;datepicker&gt; 元素。见下文。

<datepicker date-format="yyyy-MM-dd" date-max-limit="{{currentDate}}" selector="form-control">
     <input ng-model="income.date" type="text" class="form-control"  required>
</datepicker>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-06-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多