I have a JSON REST service that returns a list of periods with start dates. How can I convert the start date to javascript date?
[ {
"periodId": 1234,
"startDate": [ 2011, 12, 24]
},
{
"periodId": 5678,
"startDate": [ 2012, 12, 24]
}
]
I'm using ngResource in my service definition:
angular.module('periodservice',['ngResource']).
factory('Periods', function($resource) {
return $resource('../rest/periods', {}, {
query : {method : 'GET', params : {}, isArray : true}
});
});
The controller is pretty straight forward.
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);
});
}
Now I display the date like this instead of converting it to a proper date:
<div class="period">Period: {{period[0]}}-{{period[1]}}-{{period[2]}}</div>