Home Creating a previous and next button using JavaScript
Reply: 0

Creating a previous and next button using JavaScript

user1280
1#
user1280 Published in June 19, 2018, 2:28 pm

Using AngularJS I have data that I am getting coming in the form of an array with two objects in it. I am new and trying to figure this out.

data[
{
"something":"something1",
"something":"something1",
"something":"something1",
},
{
"something":"something2",
"something":"something2",
"something":"something2",
}
]

What I want to do is create a previous and next button that when clicked the first object will change to the second object. I know using:

current = response.data[0];

will get me the first array object. I tried something like this:

   var current = 1
  const getSessions = () => {
    loginService.getUser().then((response) => {
      var user_id = response.data.id;
      console.log("getUser returning this => ", response.data);
      loginService.getUserSessions(user_id).then((response) => {
        current = response.data[0];
        $scope.sessions = response.data;
      })
    })
  };

 getSessions();

  $scope.nextPage = function() {
    current++;
    getSessions();
}
$scope.prevPage = function (){
    if(current > 1){
        current--;
    getSessions();    
    }
}

but like I said I'm not really sure what to do.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.599816 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO