我希望每个行都增加并显示日期名称。
如何制作?
App.js
App.controller('TestCtrl', function ($scope) {
var g = ['1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30','31'];
var datastart = new Date(2014, 1, 1);
$scope.myDate = datastart;
$scope.myDays = g;
});
HTML:
<div class="row" ng-repeat="MyDay in MyDays"> // for 1 to 31
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control" value="{{ MyData | date:'EEEE'}}" />
</div>
</div>
答案 0 :(得分:0)
您应该在Javascript中构建一个表或日期(注意您的月份长度为28 - 31?):
$scope.days = [];
for (var i = 1; i <= 31; i++){
$scope.days.push(new Date(2014, 1, i);
}
然后在你的html文件中:
<div class="row" ng-repeat="day in days">
<div class="col-md-2">
<div class="form-group">
<input type="text" class="form-control" value="{{ day | date:'EEEE'}}" />
</div>
</div>
答案 1 :(得分:0)
这是一个更简单的解决方案,可以增加一天,而无需担心当月的天数。
这是一个添加日方法,它将一天的毫秒数加到/减去日期的时间戳
var dayInMS = 24 * 60 * 60 * 1000;
var toNumber = function(n) {
n = +n;
if (!n) {
n = 1;
}
return n;
};
addDay = function(date, n) {
return new Date(date.getTime() + (dayInMS * toNumber(n)));
};
var date = new Date(2014, 1, 1);
$scope.newData = addDay(date, 1);