My goal is to connect 2 Firebase queries using promises, as I require the result of the first query in order to execute the second one. Below are the details of the 2 queries:
QUERY FOR VALUE A:
private getValueA(){
var queryEvent = (result):void =>{
console.dump(result);
this._valueA = result.value;
}
return firebase.query(
queryEvent,
FirebaseValueAPath,
{
singleEvent : true,
orderBy : {
type: firebase.QueryOrderByType.CHILD,
value: 'since'
}
});
}
QUERY FOR VALUE B:
private getValueB{
let FirebaseValueBPath :string = this._valueA
var queryEvent = (result) :void =>{
console.dump(result);
if(result.value){
this._valueB = result.value;
}
}
return firebase.query(
queryEvent,
FirebaseValueBPath,
{
singleEvent : true,
orderBy : {
type : firebase.QueryOrderByType.CHILD,
value : 'since'
}
});
}
}
Next, I attempt to link them together by implementing the following :
constructor(){
this.getValueA().then(
(success) :void => {
this.getValueB();
});
}
The outcome reveals some issues:
- Oddly enough,
console.log(result)
within the getValueB function is displayed before the log from inside the getValueA function (why??) this.valueA
isundefined
ingetValueB
, rendering my query ineffective- The application crashes
Where did I go wrong in my code? Is there a different method I should be utilizing for this scenario? Appreciate your assistance on this matter :)