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

Seth Warner
Seth Warner
1,878 Points

How can I change the page id number in the query string, with angular and or plain Javascript.

So at the moment my site can flip through pages if I MANUALLY type out the id number at the end of the URL query string. I'd like to know how can I make a button that would allow me to increment that number or decrement that number, based off the number that is currently present.

Seth Kroger
Seth Kroger
56,413 Points

Are you talking about loading into a One Page App with AJAX or loading separate webpages each time?

Seth Warner
Seth Warner
1,878 Points

Seth Kroger I'm most familiar with Ajax. My app is using Angular, so Jquery is not really an option, I think. I'm thinking I need to use a POST request, right?

1 Answer

Seth Kroger
Seth Kroger
56,413 Points

If you're retrieving the page you should be using GET instead of POST within your service (ie., $http.get()).

In Angular I'd keep track of the current page in the controller with two functions for the buttons.

$scope.currentPage = 1;

$scope.nextPage = function() {
   $scope.currentPage++;
   // ...
}

$scope.prevPage = function() {
   $scope.currentPage--;
   // ...
}