I am facing an issue with calling functions of the Map (get, set, keys, etc) within my function. The map I am working with is returned from a firebase query.
Here's a snippet of my code:
categoryMap = new Map<Number, String>();
//called onInit.
loadList() {
this.firestore.firestore.collection('skillType').doc('content')
.get().then(res => {
this.categoryMap = res.data().list;
});
}
sampleFunction() {
//myMap is a dummy map that I found online.
var myMap = new Map();
myMap.set(0, 'dummy'); //the function works here.
console.log(myMap.get(0)); //Outputs as expected.
console.log(this.categoryMap.get(1)); //Throws an error message instead
}
This is the categoryMap
after executing loadList()
:
1: "Development & IT"
2: "Design & Creative"
3: "Accounting & Consulting"
4: "Translation & Language"
5: "Sales & Marketing"
6: "Sports & Fitness"
7: "Academic & Curricular"
8: "Culinary"
9: "Labor work"
The values are present in the map, so why am I unable to call any functions to retrieve my data?