Angular UI 2 datepickers范围

时间:2014-03-13 09:42:27

标签: angularjs datepicker angular-ui

当我想在范围内使用2个日历时,我对AngularUI datepicker有问题。

当我在第一个日历中选择日期时,第二个日历的最小日期需要高于第一个日历。

到目前为止没问题!

但是,当我打开第二个日历时,第一个日期很好,但我无法点击日期或无法切换月份!什么都没做......

这是我的代码

HTML:

<div ng-controller="test">
  From <input id="from" ng-model="from" ui-date="formatCalendar" ng-change="updateDate()">
  To <input id="to" ng-model="to" ui-date="formatCalendar2">
</div>

Javascript:

function test($scope){

 $scope.to = null;
 $scope.from = null;

 $scope.formatCalendar = {
    minDate: 0,
    maxDate: 365,
    defaultDate: "+1w",
    numberOfMonths: 2,
    changeMonth: true,
    dateFormat: 'dd/mm/yy'
 };

 $scope.formatCalendar2 = {
    defaultDate: "+1w",
    numberOfMonths: 2,
    changeMonth: true,
    dateFormat: 'dd/mm/yy'
  };

 $scope.updateDate = function(){
  $scope.formatCalendar2.minDate = $scope.from;
 };
}

你可以看到恶魔@ http://plnkr.co/edit/4tTHEIUzVRyQJ7NOCIAs?p=preview

感谢您的帮助:)

1 个答案:

答案 0 :(得分:0)

通过查看ui-date的来源,似乎它在整个配置对象上都有一个监视器。只有在更换配置对象时才会触发该表,如果只修改了它上面的属性则不会触发。这样的事情可能有用:

$scope.updateDate = function(){
  // Just a simple way to clone the object to trigger
  // the watch in ui-date
  $scope.formatCalendar2 = JSON.parse(JSON.stringify($scope.formatCalendar2));
  $scope.formatCalendar2.minDate = $scope.from;
};

编辑: 误读代码,手表会触发,因为getOptions()每次都会返回一个新对象。我能够让你的代码在这里运行:http://jsbin.com/yibehape/2/edit 它在更改“发件人”字段时设置“收件人”字段的最小日期。因此,我猜测您的代码中存在一些您尚未向我们展示的逻辑错误。你似乎已经删除了你的plunker,你有没有工作?