【问题标题】:Saturn Datepicker dynamic rangeMode propsSaturn Datepicker 动态范围模式道具
【发布时间】:2020-06-11 16:38:15
【问题描述】:

我有一个 angular 8 的 sat-datepicker,带有 rangemode 道具动态,当 rangeMode 为 false 并更改为 true 时它可以工作,但反之亦然,如果我选择了一个范围日期,然后我想选择一个 sngle当 rangeMode 为 false 时,抛出此错误

ERROR TypeError: date.clone is not a function
at MomentDateAdapter.push../node_modules/@angular/material-moment-adapter/esm5/material-moment-adapter.es5.js.MomentDateAdapter.clone (material-moment-adapter.es5.js:212)
at MomentDateAdapter.push../node_modules/@angular/material-moment-adapter/esm5/material-moment-adapter.es5.js.MomentDateAdapter.isValid (material-moment-adapter.es5.js:395)
at MomentDateAdapter.push../node_modules/@angular/material/esm5/core.es5.js.DateAdapter.sameDate (core.es5.js:711)
at SatDatepickerInput.set [as value] (saturn-datepicker.js:4409)
at SafeSubscriber._next (saturn-datepicker.js:4329)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.__tryOrUnsub (Subscriber.js:192)
at SafeSubscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.SafeSubscriber.next (Subscriber.js:130)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber._next (Subscriber.js:76)
at Subscriber.push../node_modules/rxjs/_esm5/internal/Subscriber.js.Subscriber.next (Subscriber.js:53)
at Subject.push../node_modules/rxjs/_esm5/internal/Subject.js.Subject.next (Subject.js:47)

【问题讨论】:

  • 我也有同样的问题,如果我找到解决方法我会回答

标签: angular datepicker date-range


【解决方案1】:

我刚刚修复了它,它有点丑,但它就像一个魅力。复制 这个文件

node_modules/@angular/material-moment-adapter/fesm5/material-moment-adapter.js

我将它复制到我的根应用程序文件夹的补丁目录中。在第 94 行编辑此文件

MomentDateAdapter.prototype.clone = function (date) {
    try {
      return date.clone().locale(this.locale);
    } catch (e) {
      return moment(date).clone().locale(this.locale);
    }
};

然后编辑你的 angular.json 文件

"fileReplacements": [
  {
    "replace": "node_modules/@angular/material-moment-adapter/fesm5/material-moment-adapter.js",
    "with": "patch/material-moment-adapter.js"
  }
],

【讨论】:

    猜你喜欢
    • 2018-06-09
    • 1970-01-01
    • 2014-04-21
    • 2014-12-21
    • 1970-01-01
    • 2011-10-02
    • 2017-04-06
    • 2018-10-03
    • 2015-08-06
    相关资源
    最近更新 更多