Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

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

share|improve this question
1  
i am not sure which array you want to parse , if it is possible make a jsfiddle –  FLF 15 hours ago
 
var result array is collecting two values then being returned. Located inside if(diff > 0). I am calling factory inside the controller but it returns [1,1] with out a way to capture either value independently. –  Alen Giliana 6 hours ago
add comment

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.