Reputation: 213
I'm new to Firebase but I need to update a prop 60 seconds after it is pushed to Firebase. How can get the dynamic key Firebase creates after a .push() is successful?
function storeData(val){
$scope.ref = new Firebase('...')
$scope.ref.push({'va1': val, 'status': 'active' });
//after push give me back the newly created key string for that item only
}
Upvotes: 0
Views: 266
Reputation: 71
Pass the key property at the end of push()
.
function storeData(val){
const dataRef = new Firebase('...')
const key = dataRef.push({'va1': val, 'status': 'active' }).key;
}
// Before returning the key value, it pushes the data to the database.
Upvotes: 1
Reputation: 213
I figured it out. I found this worked like a charm
$scope.ref.limitToLast(1).on("child_added", function(snapshot) {
console.log(snapshot.key());
})
Upvotes: 0