2015-11-30 38 views
0

我正在使用angular-material datepicker。我有一个场景,其中一个日期选择器的最短日期设置为另一个日期选择器的模型。我注意到,在第一个日期中更改日期后,不会触发采用“动态”最短日期的选择器验证。与此设置当minDate更改/动态时,Md-datepicker不显示验证错误

<h4>Standard date-picker</h4> 
<md-datepicker ng-model="minDate" md-placeholder="Enter date"></md-datepicker> 
<h4>Date-picker with min date set to first picker</h4> 
<md-datepicker ng-model="myDate" placeholder="Enter date" 
      md-min-date="minDate"></md-datepicker> 

Plunker

的成立。

当我将第一个选择器中的日期更改为第二个日期之后。带有最短日期的选取器应在无效状态。 有趣的是,由于在日历视图中禁用了最短日期之前的日期,所以第二个选择器会选择最短日期。

这是一个错误吗? 有没有解决方法?

回答

0

我已经把$watch这将检查是否minDate是否低于myDate如果是,然后重置myDate minDate。

$scope.$watch('minDate', function(newValue, oldValue){ 
    if (oldValue != newValue){ 
    if (newValue > $scope.myDate){ 
     $scope.myDate = newValue;//reset the myDate with new Value of minDate 
    } 
    } 
}); 

工作代码here

希望这有助于!