Below is my code that I used to call a function that returns a value after fetching from the Firebase ref.
let original = Promise.resolve(this.contactService.fetchContact(contact));
original.then(function(value){
console.log("original value: " + value);//point 2
});
the Firebase fetching function is as below:
fetchContact(name){
//fetch contact object from name
let contactObj = this.database.ref('path').orderByChild('name').equalTo(name).once('value').then(response=>{
console.log(response.val());//Point 1
return response.val();
});
}
The problem is, in the comment Point 1, I get the desired value as the output. But as I have returned the same to the Promise, I want it to be returned as the response in the comment Point 2. What I get is undefined
in the comment Point 2
This is not the same as that of the Ajax call or Http Requests. This is within the local files. Where am I going wrong? Please help. Thanks!