Last active
August 29, 2015 13:56
-
-
Save rikukissa/9088731 to your computer and use it in GitHub Desktop.
Example "Collection" implementation for angularFire
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function MyController($scope, $firebaseCollection) { | |
// "images" - contains for example >10 000 children and we don't want to fetch them all at once | |
var imagesRef = new Firebase("https://<my-firebase>.firebaseio.com/images"); | |
// Creates an empty collection for images | |
// Collection should now track changes in imagesRef. | |
// Example methods: | |
// $push( snapshot ) - Push new children to collection | |
$scope.images = $firebaseCollection(imagesRef); | |
// We have a view with a list of images. We only want to fetch 100 latest images. | |
imagesRef.limit(100).once('value', function(snapshot) { | |
// Push fetched images to our collection. | |
$scope.images.$push(snapshot); | |
// Now for example if a child is removed from "imagesRef" and it matches to one we just pushed to our collection, | |
// the collection removes it automatically from itself. | |
// It also tracks all changes to pushed images and updates the data automatically. | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment