【发布时间】:2016-10-06 23:59:10
【问题描述】:
这是我的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 之间的范围。任何人都可以建议如何在我的场景中执行此操作。提前致谢
【问题讨论】:
-
你在使用
moment range扩展吗? -
你想得到天数的差异吗?
-
不确定这与 Angular 有什么关系......
-
预期结果是什么,您打算在哪里使用它?
-
我需要知道'fromdate'和'todate'之间的日期是什么
标签: javascript jquery html angularjs