Reputation: 1
I have a function and call firebase database, i want get value and pass to variable declate inside function but don't work. How do this?
subObjectTable(data, cell) {
...
const database = fire.database();
let nome;
database
.ref(`/proprietários/${getProp}`)
.on('value', snapshot => {
let data = snapshot.val();
nome = data.Nome;
})
console.log('nome', nome) // undefined
}
Upvotes: 0
Views: 290
Reputation: 317372
Firebase APIs are asynchronous and return immediately. The results of your query will be delivered some time later with the results of your query. subObjectTable
will have fully completed by the time the first callback occurs.
If you want to do something with the value of nome
, you'll have to do it inside the function callback that you pass to on()
, or call some other function from there.
Upvotes: 2