Reputation: 732
The below code is for pagination in HTML:
<button ng-disabled="" ng-click="previousPage(limit,offset)">
Previous
</button>
<button ng-disabled="" ng-click="nextPage(limit,offset)">
Next
</button>
In controller file:
$scope.previousPage=function(limit,offset){
adminservice.getPagination().then(function(response){
adminservice.showAllVehicleDetails().then(function(){
$scope.vehicledetails=response.data[0][limit-10][offset+10];
console.log('limitNumber',limit)
console.log('offsetNumber',offset)
});
});
}
$scope.nextPage=function(limit,offset){
adminservice.getPagination().then(function(response){
adminservice.showAllVehicleDetails().then(function(){
$scope.vehicledetails=response.data[0][limit+10][offset-10];
});
});
}
In service file:
var getPagination=function(){
return $http({
url:apiurl+'paginatedetails',
method:"GET",
params:{limitNumber:limit,offsetNumber:offset}
});
}
Can anyone show me the correct way to do it? When I'm running this code, the console shows error like: limit is not defined at Object.getPagination
.
Upvotes: 0
Views: 50
Reputation: 74738
I suppose you have to pass the limit
and offset
back to service at each click
call:
var getPagination=function(limit, offset){
return $http({
url:apiurl+'paginatedetails',
method:"GET",
params:{limitNumber:limit,offsetNumber:offset}
});
}
Now in the click function pass the arguments:
adminservice.getPagination(limit, offset)....
Upvotes: 0
Reputation: 1379
In controller file, you have to pass limit,offset to adminservice.getPagination(limit,offset)
$scope.previousPage=function(limit,offset){
adminservice.getPagination(limit,offset).then(function(response){
adminservice.showAllVehicleDetails().then(function(){
$scope.vehicledetails=response.data[0][limit-10][offset+10];
console.log('limitNumber',limit)
console.log('offsetNumber',offset)
});
});
}
$scope.nextPage=function(limit,offset){
adminservice.getPagination(limit,offset).then(function(response){
adminservice.showAllVehicleDetails().then(function(){
$scope.vehicledetails=response.data[0][limit+10][offset-10];
});
});
}
And in service file you have to also write like this
var getPagination=function(limit,offset){
return $http({
url:apiurl+'paginatedetails',
method:"GET",
params:{limitNumber:limit,offsetNumber:offset}
});
}
I think this work fine.
Upvotes: 1