Currently, I am utilizing a native script firebase plugin that requires the following function:
getCompanyValue() {
var value;
firebase.getValue('/companies')
.then(result => {
console.log(JSON.stringify(result));
value = result;
return result;
})
.catch(error => {
console.log("Error: " + error);
return error;
});
return value;
}
When importing this function into another file and using it like so:
var companyValue = this.myFirebaseService.getCompanyValue();
The first time I run it, it returns 'undefined', but on subsequent runs, it returns the actual value.
My inquiry is how can I modify the firebase function to return a promise, allowing me to make my second statement wait for its completion?