我已经用我的 angular2 应用程序配置了 moment,当我试图将本周星期六的日期分配给日期类型变量时,
case "weekend":
this.fromDate = moment().startOf('week');
它显示错误说,
Type 'Moment' is not assignable to type 'Date'. Property 'toDateString' is missing in type 'Moment'
我在我的组件中导入了如下时刻,
import * as moment from 'moment/moment';
最佳答案
startOf
:
Mutates the original moment by setting it to the start of a unit of time
所以它返回一个力矩对象。使用 toDate()
如果您需要转换为 JavaScript 日期。
case "weekend":
this.fromDate = moment().startOf('week').toDate();
关于angular - 类型 'Moment' 不可分配给类型 'Date' 。类型 'toDateString' 中缺少属性 'Moment',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42161854/