这是我的 html 页面
<tr ng-show="option == 'Yearly' || option == 'Date'">
<td>
<label>From:</label>
</td>
<td>
<input type="text" ng-model="fromdate" id="from" date-picker date-type="from" month-directive />
{{fromdate}}
</td>
<td>
<label>To:</label>
</td>
<td>
<input id="todate" type="text" ng-model="todate" date-picker date-type="to" month-directive />
{{todate}}
</td>
</tr>
这是我的指令
app.directive('monthDirective', function () {
return {
restrict:'A',
link: function (scope, elem) {
var fromDate, toDate;
scope.$watch('fromdate', function (newValue, oldValue) {
fromDate = newValue;
console.log('fromDate', newValue);
});
scope.$watch('todate', function (newValue, oldValue) {
todate = newValue;
console.log('todate', newValue);
});
var range = moment().range(fromDate, toDate);
var diff = moment.preciseDiff(fromDate,toDate);
console.log('Range', range);
console.log('diff', diff);
}
}
})
我需要使用 mument.js 获取 fromdate 和 todate 之间的范围。任何人都可以建议如何在我的场景中执行此操作。提前致谢
原文由 user6269870 发布,翻译遵循 CC BY-SA 4.0 许可协议
要获取两个日期之间的其余日期,您可以参考此代码 -
这是控制台日志:-