開始日を含む期間のリストを返す JSON REST サービスがあります。開始日をJavaScriptの日付に変換するにはどうすればよいですか?
[ {
"periodId": 1234,
"startDate": [ 2011, 12, 24]
},
{
"periodId": 5678,
"startDate": [ 2012, 12, 24]
}
]
サービス定義で ngResource を使用しています。
angular.module('periodservice',['ngResource']).
factory('Periods', function($resource) {
return $resource('../rest/periods', {}, {
query : {method : 'GET', params : {}, isArray : true}
});
});
コントローラーはかなり単純です。
function EksternVareRedigeringCtrl ($scope, Periods){
$scope.periods = Periods.query(function(success, status, headers){
$scope.msgf = success;
console.log("this is the succsess);
}, function(errors){
$scope.msgf = errors;
console.log("This is an error....." + ' ' + $scope.msgf.status);
});
}
適切な日付に変換する代わりに、次のように日付を表示します。
<div class="period">Period: {{period[0]}}-{{period[1]}}-{{period[2]}}</div>