4

I am using AngularJS and FireBase in my application. I bound an object to be in sync with FireBase:

$scope.winnerPromise = angularFire(travelBidsFirebaseRef + "/user/" + $scope.auction.winnerUserId, $scope, 'winner', {});

Now I want to disassociate $scope.winner, meaning I want it to stay safe in the FireBase DB, but I don't want my scope variable 'winner' to be synchronized with it anymore. How do I do that? I saw disassociate() finction in angularfire.js but I don't see how I can use it. Any ideas?

Alexander Burakevych
  • 2,396
  • 1
  • 24
  • 25

2 Answers2

2

The disassociate function is passed to you when the promise is resolved. I'd use it as follows:

var ref = travelBidsFirebaseRef.child("user/" + $scope.auction.winnerUserId);
var promise = angularFire(ref, $scope, "winner", {});
promise.then(function(disassociate) {
  // Do some work...
  disassociate(); // Don't synchronize $scope.winner anymore.
});

Hope this helps!

Anant
  • 7,408
  • 1
  • 30
  • 30
  • It helped, thanks! It would be great to have the disassociate() function attached to the scope object, e.g. $scope.winner.disassociate(); since it's often not the case that all code is inside the promise.then() function. I actually tried to do so: $scope.winner.disassociate = disassociate; However, the bound scope object references (e.g. $scope.winner) are reassigned with a new object every time the object changes. – Alexander Burakevych Aug 11 '13 at 09:52
  • Yes, unfortunately due to the way changes to objects are observed by Angular, I don't recommend attaching functions to $scope objects that are bound to Firebase URLs. You may store the function under a seperate $scope variable though, like $scope.disassociateWinner() – Anant Aug 12 '13 at 18:16
0

I am using angularfire and for me it worked the $destroy method.

https://github.com/firebase/angularfire/blob/master/docs/reference.md#destroy-1

Andre Evangelista
  • 3,390
  • 1
  • 21
  • 14