0

I've just started seeing this error in Angular.js (1.5)

Error: Duplicates in a repeater are not allowed. Repeater: day in forecast key: string:o
at ngRepeatAction (url...)

The strange thing is, that this error shows up in the console before the array of the forecast has been returned.

When the array is returned, it is a unique array

[{"print_date":"Tue","long_day":"Tuesday","weather":{"conditions":"Clouds","temps":{"current":19,"max":20,"min":16}}},
{"print_date":"Wed","long_day":"Wednesday","weather":{"conditions":"Clouds","temps":{"current":22,"max":24,"min":15}}},
{"print_date":"Thu","long_day":"Thursday","weather":{"conditions":"Clouds","temps":{"current":22,"max":22,"min":18}}},
{"print_date":"Fri","long_day":"Friday","weather":{"conditions":"Rain","temps":{"current":22,"max":23,"min":18}}},
{"print_date":"Sat","long_day":"Saturday","weather":{"conditions":"Rain","temps":{"current":22,"max":23,"min":15}}}]

The forecast array is built via

$scope.forecast = (function(){
        var day_list=[];
        for(var d in forecast.data.list){
        var day_weather = formatForecast(forecast.data.list[d],date);
        day_list.push(day_weather);
        }
        return day_list;
    })();

2 Answers 2

0

Never ever ever do a for in loop when you just want to access the members in the array. The for in loop should be used when you are going through the properties of an object, NOT the members of the array. See what happens when you do a normal for loop instead. Your format forecast is likely creating two identical objects

Sign up to request clarification or add additional context in comments.

1 Comment

I changed it to use a regular for loop, but still get the same error.
0

Turns out, I had defined the $scope.forecast as 'loading weather', as a string, and then was replacing it with an array, so angular was converting the string to an array and then noticing that there are duplicate letters.

Stupid mistake on my part, hopefully this helps somebody else.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.