Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Building with AngularJS and APIs

Can't get the page number right.

When passing page parameter with +1 to call for next page, function is calling for page 11 instead of page 2. It's calling for http://api.dribbble.com/shots/everyone?callback=angular.callbacks._2&page=11 where it should have been

http://api.dribbble.com/shots/everyone?callback=angular.callbacks._2&page=2.

function in use- $scope.loadNextPage = function () { dribbble.list(list, {page: $scope.list.page + 1}).then(function(data){ $scope.list.page = data.data.page; $scope.list.shots = $scope.list.shots.concat(data.data.shots); }); };

What could be the solution for this?

Thanks in advance.

2 Answers

I'm wondering if you're concatenating when you think you're mathematically adding. If your variable already has the value "1", i.e. a string, and you add the number (integer) 1 to it, it will coerce it into a string and concatenate the two values together. So "1" + 1 will equal "11", and not 2. To get 2 you'd need to add the integer 1 to another integer 1.

Just a guess.

Used parseInt() to convert into number and it worked. Cheers.