Upon receiving a response from Firestore via onSnapshot, I retrieve 2 records and store them in an array called shop.
this.db.collection("Countries").doc("AU")
.collection("cPostcode").doc(this.searchby)
.collection(this.shop).where(how, '==', true)
.onSnapshot(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
shop.push(doc.data());
})
});
console.log('shop.length', shop.length, 'Shop', shop);
if (shop.length) {
this.shopList = shop; .........
To check if any data has been returned, I use shop.length > 0
, however, despite having 2 items in the array, shop.length
shows as 0.
The output from the console log displays length: 2
-
shop.length 0 shop []
0:{ABN: "1", ACN: "2"}
1:{ABN: "3", ACN: "4"}
length:2
__proto__:Array(0)
I attempted to include a flag within the forEach loop, but it goes out of scope causing issues with the "this.count" variable that I also tried. This has been an ongoing struggle for me over several days. Despite searching through Google for assistance and tips regarding Typescript, I have not found anyone else encountering this issue. What could I possibly be doing wrong?