I am performing an operation in angularfire2 where I subscribe to angularfire.auth in order to retrieve the user id for the currently signed in user using the following code:
angularfire.auth.subscribe(auth => {
this.userId = auth.uid;
console.log(this.userId);
}
This works successfully and assigns the uid to the local variable userId.
The problem I am having is when I wish to perform the following code:
let shipObservable = angularfire.database.list('/ships/' + this.userId);
shipObservable.subscribe(
value => {
this.otherObservable = angularfire.database.list('/other/' + value[0].otherId);
this.otherObservable.subscribe(value => {
this.address = value[0].$value;
this.number = value[1].$value;
this.email = value[2].$value;
this.name = value[3].$value;
});
}).catch((err) => console.log(err));
The issue is that the second piece of code runs before I get the uid back from the first observable. I am aware that these are asynchronous operations and may come back at anytime. But I would like to know is there a way to ensure that the second observable executes after the user id has been assigned to the uid returned by auth.