Skip to content

Instantly share code, notes, and snippets.

@katowulf
Last active October 13, 2015 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save katowulf/8eaa39eab05a4d975cd9 to your computer and use it in GitHub Desktop.
Save katowulf/8eaa39eab05a4d975cd9 to your computer and use it in GitHub Desktop.
Reset method on a $FirebaseArray in AngularFire
var ResetFactory = $FirebaseArray.$extendFactory({
reset: function(itemOrIndex) {
var self = this;
var key = self.$keyAt(itemOrIndex);
self.$inst().$ref().once('value', function(snap) {
self.$$updated(snap);
});
}
});
@danielcha
Copy link

Hi katowolf,

Great snippets! A small suggestion: could you add the current version of Firebase, AngularFire etc with each snipped. I tried to use this and it failed because Firebase is changing rapidly (which is a good thing).

I was able to modify your code for the current version of Firebase and AngularFire (2.3.1 and 1.1.3). I hope this helps someone:

app.factory('ResetFactory', function($firebaseArray) {
    return $firebaseArray.$extend({
        reset: function(itemOrIndex) {
            var key, self;
            self = this;
            key = self.$keyAt(itemOrIndex);
            self.$ref().child(key).once('value', function(snap) {
               self.$$updated(snap);
            });
        }
    });
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment