简体   繁体   中英

Get Current value of a Firebase Node? (Using AngularJS)

Trying to update the information in a node by adding an amount to the current value. I can't find a way to reference the current value so I can add my value. How can you call the current value?

.update({total: "current-value?" + $scope.user.amount}).then(function() {       
    });

As it looks like you might not be able to pull the current value of a node without using a function, that is what I did:

snap.ref().child('gold/total').transaction(function(currentVal) {
        return (currentVal || 0) + $scope.user.amount;
     }); 

The current value of the node is captured with "currentVal", and then it can be passed along so that the addition can be performed.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM