I'm trying to create an infinite list with the Ionic / AngularJS. This list passes a offset
to my webservice to page the SELECT
responses. I can not do this and I'm looking for an example but I have not found it yet.
I'm trying like this.
Service
var app = angular.module('starter');
app.service('EmpresaAPIService', function($http, AppConstants, HeaderFactory){
var headersJSON = HeaderFactory.getHeader.headerJSON();
this.getAllEmpresas = function(offset){
var _url = AppConstants.webServiceUrl + "/empresas/getAllEmpresas.json";
var _jsonData = {"offset": offset};
return $http.post(_url, _jsonData, {
headers: headersJSON,
});
};
});
Controller
var app = angular.module('starter');
app.controller('EmpresaCtrl', function($scope, EmpresaAPIService){
var offset = 0;
$scope.items = [];
$scope.addItems = function(){
EmpresaAPIService.getAllEmpresas(offset)
.success(function(data){
var result = data.result;
for(var x = 0; x < result.length; x++){
$scope.items.push(result[x].Empresa);
}
offset += 5;
//console.log(result[0].Empresa.nomeFantasia);
})
.error(function(err){
console.log(err);
});
};
});
Html
<ion-view title="Empresas">
<ion-content class="has-header padding">
<ion-list>
<ion-item ng-repeat="item in items track by $index">
<p>{{item.nomeFantasia}}</p>
</ion-item>
<ion-infinite-scroll on-infinite="addItems()" distance="1%"></ion-infinite-scroll>
</ion-list>
</ion-content>
</ion-view>