Infinite scroll using firebase snapshot


#1

I am trying to figure out how to use ionic infinite scroll using firebase data snapshot so I can retrieve images associated with the user.

Here is my code to get the snapshot. How can I call it so it loads only 4 at a time?

   getWardrobeFeed: function(){
      var defered = $q.defer();
      var user = User.getLoggedInUser();
      var wardrobeKeyRef = new Firebase(FIREBASE_URL + '/userProfile/' + user.uid + '/wardrobe');
      wardrobeKeyRef.orderByChild('timestamp').limitToLast(2).on('child_added', function (snap) {
        var imageId = snap.key();
        userImageRef.child(imageId).on('value', function (snap) {
          $timeout(function () {
            if (snap.val() === null) {
              delete userWardrobeFeed[imageId];
            } else {
              userWardrobeFeed[imageId] = snap.val();
            }
          });
        });
      });
      wardrobeKeyRef.orderByChild('timestamp').limitToLast(2).on('child_removed', function (snap) {
        var imageId = snap.key();
        $timeout(function (snap) {
          delete userWardrobeFeed[imageId];

        });
      });
      //return ;
      defered.resolve(userWardrobeFeed);
      start = start + n;
      end = end + n;
      return defered.promise;
    }