如何动态设置datetimepicker选项

时间:2016-01-07 19:15:41

标签: javascript angularjs

我正在尝试设置this datetimepicker插件的选项,但我需要它是动态的。

这是我控制器中的这个

  $(document).ready(function () {

    var today = moment(new Date()).format("YYYY-MM-DD");
    var tomorrow = moment().add(1, 'days');

    $scope.datetimepickerOptions = {
      format: "YYYY-MM-DD",
      defaultDate: today // here I need to set today or tomorrow
    };

 });

这里是我的HTML

// today option should be here
<input datetimepicker
       datetimepicker-options="{{datetimepickerOptions}}"/>

// tomorrow option should be here
<input datetimepicker
       datetimepicker-options="{{datetimepickerOptions}}"/>

选项是设置输入/字段的初始值,在第一个我需要设置今天的日期,以便用户可以看到它,而在第二个,它应该是tomorro&#39; s日期。

你推荐什么?

修改

我这样做了

    $scope.datetimepickerOptions = {
      todayOptions: {
        format: "YYYY-MM-DD",
        defaultDate: today
      },
      tomorrowOptions: {
        format: "YYYY-MM-DD",
        defaultDate: tomorrow
      }
    };

但我收到此错误

TypeError: option todayOptions is not recognized!

1 个答案:

答案 0 :(得分:0)

如何将您的选项分成两组?

$scope.datetimepickerOptions1 = {
      format: "YYYY-MM-DD",
      defaultDate: today
    };

$scope.datetimepickerOptions2 = {
      format: "YYYY-MM-DD",
      defaultDate: tomorrow 
    };