I am currently working with AngularJS and I have data that is being received in the form of an array containing two objects. As a newcomer, I am still trying to figure this out.
data[
{
"something":"something1",
"something":"something1",
"something":"something1",
},
{
"something":"something2",
"something":"something2",
"something":"something2",
}
]
My goal is to create previous and next buttons that, when clicked, will transition from the first object to the second object. I am aware that by using:
current = response.data[0];
I can access the first object in the array. I attempted code similar to 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();
}
}
However, I am still uncertain about the best approach to take.