I´m trying to implement a pagination service. So, in a controller I have two methods to get a list of boats from my database (using a Rails API). To get the data the controller is using a service with a resource (simple query method):
.factory('Boat',
function($resource){
var boats =
$resource('http://127.0.0.1\\:3000/:action', {}, {
query: {method:'GET', params:{action:'boats'}, isArray:true},
getBoatsByBusinessId: {method:'GET', params:{action:'boatsByBusinessId'}, isArray:true}
});
return boats;
}
)
In my controller, I have two methods (maybe I could use just one, but I think this is not important this point):
$scope.getOptionList = function(departure, departureDate, arrivalDate, people) {
$scope.pagIndex = 0;
$scope.boats = Boat.query({pagIndex: $scope.pagIndex}); // List of boats is filled correctly
};
and OPTION_1:
$scope.moreResultsBoats = function() {
$scope.pagIndex = $scope.pagIndex + 1;
$scope.moreBoats = Boat.query({pagIndex: $scope.pagIndex});
console.log("moreBoats:" + $scope.moreBoats);
angular.forEach($scope.moreBoats, function(boat, key) {
$scope.boats.push(boat);
});
}
or OPTION_2:
$scope.moreResultsBoats = function() {
$scope.pagIndex = $scope.pagIndex + 1;
$scope.moreBoats = Boat.query({pagIndex: $scope.pagIndex});
console.log("moreBoats:" + $scope.moreBoats);
$scope.boats.push.apply($scope.boats, $scope.moreBoats);
}
Neither of the OPTIONS add the array of new boats in $scope.moreBoats to the $scope.boats (or at least the view is not refreshed).
I think I don´t understand something about how AngularJS works, because console.log only displays this: moreBoats:.
However, if I add {{moreBoats | json }} to my view, for tracking purposes, I can see the boats in json when they come.
What am I missing?
Thanks, Roberto.