When the ngOnInit()
function is called, the first line of code retrieves a value
from local storage which is then used to filter
data from the database.
Both actions happen simultaneously, resulting in an issue where I don't receive the expected result. How can I make the second function wait for the first one to retrieve the value?
Here is the ts
code snippet:
ngOnInit() {
//get id of user
this.storage.get('loggedInUser').then((val) => {
console.log('Your user ID is', val);
this.loggedInusr = val;
});
firebase.firestore().collection(`todos`)
.where("assignTo", "==", this.loggedInusr) // doesn't get value here, works if hard coded
.get()
.then(querySnapshot => {
querySnapshot.forEach(function(doc) {
console.log("assignTo");
console.log(doc.id, " ===> ", doc.data());
});
});
...