I tried to return data after update in firebase but it is displaying as undefined
test().then((res) => {
alert(res);
});
test() {
var fredNameRef = new Firebase('');
var onComplete = function(error) {
if (error) {
return error;
} else {
return "success";
}
};
fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete);
}
I tried to return data after update in firebase but it is displaying as undefined
test().then((res) => {
alert(res);
});
test() {
var fredNameRef = new Firebase('https://docs-examples.firebaseio./samplechat/users/fred/name');
var onComplete = function(error) {
if (error) {
return error;
} else {
return "success";
}
};
fredNameRef.update({ first: 'Wilma', last: 'Flintstone' }, onComplete);
}
Share
Improve this question
asked Mar 19, 2016 at 18:46
Akash RaoAkash Rao
9283 gold badges12 silver badges25 bronze badges
1 Answer
Reset to default 8The onComplete
callback is used to check for errors during the update, not to receive the data.
The Firebase SDK surfaces update first locally, and then if successful it fires the onComplete
callback.
In your case you want to save the data and then listen for the update using the .on()
method.
var fredNameRef = new Firebase('https://docs-examples.firebaseio./samplechat/users/fred/name');
fredNameRef.on('value', function(snap) {
console.log(snap.val());
});
fredNameRef.update({ first: 'Wilma', last: 'Flintstone' });
After the .update()
method is executed, it will trigger the .on()
method.