You're trying to implement infinite scrolling.
Here's my simple solution which implies pagination support on the back-end:
Coffeescript:
angular.module('yourApp.controllers').controller 'InfiniteCtrl',
['$resource', '$scope', 'DataResource',
($resource, $scope, DataResource) ->
new class InfiniteCtrl
constructor: () ->
$scope.myData = []
@counter = 0
@loadMore()
loadMore: () ->
@counter += 1
@DataResource.get({page:@counter}).$promise.then (data) ->
$scope.myData = $scope.jobs.concat(data)
]
Compiled JS:
angular.module('yourApp.controllers').controller('InfiniteCtrl', [
'$resource', '$scope', 'DataResource', function($resource, $scope, DataResource) {
var InfiniteCtrl;
return new (InfiniteCtrl = (function() {
function InfiniteCtrl() {
$scope.myData = [];
this.counter = 0;
this.loadMore();
}
InfiniteCtrl.prototype.loadMore = function() {
this.counter += 1;
return this.DataResource.get({
page: this.counter
}).$promise.then(function(data) {
return $scope.myData = $scope.jobs.concat(data);
});
};
return InfiniteCtrl;
})());
}
]);
You can adapt this solution to limit the amount of items you show.
In your template, showing more data can be done with :
<button ng-click="ctrl.loadMore()">More!</button>