Reputation: 2436
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?
Upvotes: 2
Views: 1640
Reputation: 7428
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 = ...
});
});
Upvotes: 2