Hello,
I'm having trouble retrieving the value of an Object in Firebase Database.
I have the following object in base:
I would like to retrieve the value of lastId (108) and then save it in the list of Words objects with the last id +1. used as a sequence of the database, because the list of Words will serve to feed an Android app)
I made the following code:
var words = firebase.database().ref('Words/');
const list = $firebaseArray(words);
$scope.addWord = function (word) {
var id;
var wdRef = firebase.database().ref('WordsDetail');
wdRef.on('value', function(snap) {
id = snap.val().lastId;
});
words.push({
//idWord: list.length + 1,
idWord: id,//quero usar o id que recuperei aqui!
word: word.word,
description: word.description
});
delete $scope.word;
$scope.wordForm.$setPristine();
}
But the variable id does not hold the value.
Would anyone know how to do this?