2
votes

I am using AngularJS and FireBase in my app. I like binding FireBase object references to the Angular scope with angularFire, but if I want to perform an update of the bound scope object in transaction - I have to create a new FireBase reference which kills all the beauty of using angularFire and increases a chance for potential issues since there are two references pointing to the same FireBase object:

        angularFire(travelBidsFirebaseRef + "/auction/" + $scope.auctionId, $scope, 'auction', {})
        .then(function(disassociate) {
                $scope.auctionRef = travelBidsFirebaseRef.child('auction/' + $scope.auction.id);
        ...

                $scope.auctionRef.transaction(function(auction) {
                    auction.price = Math.round((auction.price + 0.01) * 100)/100;
                });
        ...
        }

Is there a way to use angularFire bound scope object to perform the transaction?

1

1 Answers

2
votes

AngularFire will accept a firebaseRef as the first argument, so the recommended approach is to use that to perform transactions:

var ref = new Firebase("https://my-firebase.firebaseio.com/auction/" + $scope.auctionId);
angularFire(ref, $scope, "auction", {}).then(function() {
  ref.transaction(function(auction) {
    auction.price = ...
  });
});