I am having difficulty parsing an array being returned by factory in Angular.js. I can see the array in console.log, but it shows that it is labeled as $$v with the correct values.
emanuel.factory('DayService', function($http, $q){
var obj = {};
obj.oscWeek = function(d){
//receives a date format mm/dd/yyyy
var promise = $q.defer();
//retrieves JSON calendar of seasons
$http.get('content/calendar.json').success(function(data) {
var temp ='';
for (var i=0; i<data.calendar.seasons.season.length; i++){
var day = new Date(d).getTime();
var end = new Date(data.calendar.seasons.season[i].end);
end.setHours(23,59);
end = end.getTime();
var diff = end - day;
diff = diff /(1000*60*60*24);
//find season that the date is in
if (parseFloat(diff) > 0){
var start = new Date(data.calendar.seasons.season[i].start);
start = start.getTime();
var temp = day - start;
var week = parseInt(temp /(1000*60*60*24*7)+1);
//creates array week in season and distance from start
var result = new Array(week, temp);
promise.resolve(result);
break;
}
}
});
//returns array in promise object
return promise.promise;
}
return obj;
});
Here is the controller that accesses the factory.
emanuel.controller('WeekdayMorning', function($scope, DayService){
$scope.week = 'days difference';
$scope.display = function(d) {
var date;
if(d=='today'){
date = new Date();
} else {
date = $scope.date;
}
$scope.week = DayService.oscWeek(date);
console.log($scope.week);
}
});
Thanks in advance. AJG