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
anguswhiston
17,225 PointsAngularJS workshop: concat issue
In the workshop we eventually get to a point of adding new pages. The code is below. The problem I'm having is that instead of adding 1 to the page number... so page 1 goes to page 2, it goes from page 1 to page 11 to page 111.
Has anyone worked through this that fixed / had this issue?
var a = parseInt("1");
$scope.loadNextPage = function (){
dribbble.list(list, {page: $scope.list.page + 1}).then(function (data){
console.log(data);
$scope.list.page = data.data.page;
$scope.list.shots = $scope.list.shots.concat(data.data.shots);
});
}
1 Answer
Aaron Graham
18,033 PointsI haven't had any direct experience with this, so I can't say for sure, but my guess would be that $scope.list.page is a string and is causing + 1 to be evaluated in string context. I think you were on the right track with the parseInt(), you were probably just using it in the wrong place. You might try something like: {page: parseInt($scope.list.page) + 1}
anguswhiston
17,225 Pointsperfect!
anguswhiston
17,225 Pointsanguswhiston
17,225 Pointssorry ignore my declaration of a variable above the code, that was me just trying to fix it by using a variable instead of a number. That didn't work either.