What I'm using
- Angular
- Firebase
What I'm trying to do
Check a firebase node to see if a user ID is true / exists
If it is, display a list of items from another node
Issues
- I have these two pieces of functionality working independently
- I can check a user node to see if they exist and write to the console
- I can display a list of items
- I cannot however, check the user and THEN display the list of items
This is the code that checks a 'members' node
This is what i use to see if the user key exists under members > project id
var userId = firebase.auth().currentUser.uid;
var pathToCheck = '/members/' + this.projectId + '/' + userId;
firebase.database().ref(pathToCheck).once('value').then(function (snapshot) {
if (snapshot.exists()) {
console.log('hooplar!');
} else {
console.log('hmmm');
}
});
}
This is how I display items
this.activatedRoute.data.subscribe((
data: { issueListData: any }) => {
this.issuesList = data.issueListData;
});
What I'd like to happen
Ideally, this is the functionality I would like, but the following error is thrown:
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'activatedRoute' of undefined
var userId = firebase.auth().currentUser.uid;
var pathToCheck = '/members/' + this.projectId + '/' + userId;
firebase.database().ref(pathToCheck).once('value').then(function (snapshot) {
if (snapshot.exists()) {
this.activatedRoute.data.subscribe((
data: { issueListData: any }) => {
this.issuesList = data.issueListData;
});
console.log('hooplar!');
} else {
console.log('hmmm');
}
});
}