【问题标题】:md-datepicker seems like not recognizing the md-max-date attributemd-datepicker 似乎无法识别 md-max-date 属性
【发布时间】:2020-05-02 05:12:39
【问题描述】:

我正在尝试设置最大结帐日期,但我的 md-max-date 无法正常工作。以下代码

<md-datepicker ng-model="model.checkInDate" md-min-date="today" ng-change="changeDate()" required md-hide-icons="calendar" md-placeholder="Enter date"></md-datepicker>

<md-datepicker ng-model="model.checkOutDate" md-min-date="model.checkInDate" md-max-date="model.maxCheckOutdate" ng-change="changeNight()" required md-hide-icons="calendar"></md-datepicker>

ChangeDate: function (checkInDate, night) {
                var model = {
                    checkOutDate: null,
                    tomorrow: null,
                    minCheckIndate: null,
                    maxCheckOutdate: null
                };

                model.checkOutDate = new Date(checkInDate).addDays(night);
                model.tomorrow = new Date(checkInDate).addDays(1);
                model.minCheckIndate = new Date(checkInDate).addDays(-1);
                model.maxCheckOutdate = new Date(checkInDate).addDays(60);
                console.log(model.maxCheckOutdate, "max date");

                return model;
            },

我为什么会得到这个?

【问题讨论】:

    标签: angularjs datepicker angular-material maxdate


    【解决方案1】:

    您需要将模型绑定到您的范围。 changeDate 函数正在返回模型,但它在哪里绑定?

    如果不绑定它,模板范围就没有可用的“模型”。

    试试$scope.model =...,而不是var model =...,这取决于您如何设置控制器。

    【讨论】:

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